mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
paste: Use a single buffer
This commit is contained in:
parent
85a81d328a
commit
ad4c5d3357
1 changed files with 10 additions and 7 deletions
|
@ -93,17 +93,17 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) -> UResult<()>
|
||||||
let stdout = stdout();
|
let stdout = stdout();
|
||||||
let mut stdout = stdout.lock();
|
let mut stdout = stdout.lock();
|
||||||
|
|
||||||
let mut line = String::new();
|
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
if serial {
|
if serial {
|
||||||
for file in &mut files {
|
for file in &mut files {
|
||||||
output.clear();
|
output.clear();
|
||||||
loop {
|
loop {
|
||||||
line.clear();
|
match read_line(file.as_mut(), &mut output) {
|
||||||
match read_line(file.as_mut(), &mut line) {
|
|
||||||
Ok(0) => break,
|
Ok(0) => break,
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
output.push_str(line.trim_end());
|
if output.ends_with('\n') {
|
||||||
|
output.pop();
|
||||||
|
}
|
||||||
output.push(delimiters[delim_count % delimiters.len()]);
|
output.push(delimiters[delim_count % delimiters.len()]);
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e.map_err_context(String::new)),
|
Err(e) => return Err(e.map_err_context(String::new)),
|
||||||
|
@ -122,13 +122,16 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) -> UResult<()>
|
||||||
if eof[i] {
|
if eof[i] {
|
||||||
eof_count += 1;
|
eof_count += 1;
|
||||||
} else {
|
} else {
|
||||||
line.clear();
|
match read_line(file.as_mut(), &mut output) {
|
||||||
match read_line(file.as_mut(), &mut line) {
|
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
eof[i] = true;
|
eof[i] = true;
|
||||||
eof_count += 1;
|
eof_count += 1;
|
||||||
}
|
}
|
||||||
Ok(_) => output.push_str(line.trim_end()),
|
Ok(_) => {
|
||||||
|
if output.ends_with('\n') {
|
||||||
|
output.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(e) => return Err(e.map_err_context(String::new)),
|
Err(e) => return Err(e.map_err_context(String::new)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue