Repository navigation
Conversation
140a726 to
e1837a0
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
57f5452 to
1c0f20e
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
Merging this PR will improve performance by ×4.4
Performance Changes
Comparing Footnotes
|
| // Handle filenames as raw bytes to support non-UTF-8 paths | ||
| #[cfg(unix)] | ||
| let filename = { | ||
| use std::os::unix::ffi::OsStrExt; | ||
| OsStr::from_bytes(&line).to_owned() | ||
| }; | ||
| #[cfg(not(unix))] | ||
| let filename = { | ||
| // On non-Unix systems, convert to UTF-8 with replacement chars | ||
| match std::str::from_utf8(&line) { | ||
| Ok(s) => OsString::from(s), | ||
| Err(_) => OsString::from(String::from_utf8_lossy(&line).into_owned()), | ||
| } | ||
| "" => { | ||
| return Err(SortError::ZeroLengthFileName { | ||
| file: files0_from, | ||
| line_num: line_num + 1, | ||
| } | ||
| .into()); | ||
| }; | ||
|
|
||
| // Check for special cases using bytes comparison | ||
| if line == b"-" { | ||
| return Err(SortError::MinusInStdIn.into()); | ||
| } | ||
| if line.is_empty() { | ||
| return Err(SortError::ZeroLengthFileName { | ||
| file: files0_from, | ||
| line_num: line_num + 1, | ||
| } | ||
| _ => {} | ||
| .into()); | ||
| } | ||
|
|
||
| files.push(OsString::from( | ||
| std::str::from_utf8(&line) | ||
| .expect("Could not parse string from zero terminated input."), | ||
| )); | ||
| files.push(filename); |
There was a problem hiding this comment.
The platform-specific code can be simplified using the existing uucore::os_string_from_vec helper, I was testing this locally. The only thing that would be functionally different is that it would error instead of doing lossy string conversion on non-unix which is what is done in a bunch of other utilities
| // Handle filenames as raw bytes to support non-UTF-8 paths | |
| #[cfg(unix)] | |
| let filename = { | |
| use std::os::unix::ffi::OsStrExt; | |
| OsStr::from_bytes(&line).to_owned() | |
| }; | |
| #[cfg(not(unix))] | |
| let filename = { | |
| // On non-Unix systems, convert to UTF-8 with replacement chars | |
| match std::str::from_utf8(&line) { | |
| Ok(s) => OsString::from(s), | |
| Err(_) => OsString::from(String::from_utf8_lossy(&line).into_owned()), | |
| } | |
| "" => { | |
| return Err(SortError::ZeroLengthFileName { | |
| file: files0_from, | |
| line_num: line_num + 1, | |
| } | |
| .into()); | |
| }; | |
| // Check for special cases using bytes comparison | |
| if line == b"-" { | |
| return Err(SortError::MinusInStdIn.into()); | |
| } | |
| if line.is_empty() { | |
| return Err(SortError::ZeroLengthFileName { | |
| file: files0_from, | |
| line_num: line_num + 1, | |
| } | |
| _ => {} | |
| .into()); | |
| } | |
| files.push(OsString::from( | |
| std::str::from_utf8(&line) | |
| .expect("Could not parse string from zero terminated input."), | |
| )); | |
| files.push(filename); | |
| for (line_num, line) in buf_reader.split(b'\0').flatten().enumerate() { | |
| // Check for special cases using bytes comparison | |
| if line == b"-" { | |
| return Err(SortError::MinusInStdIn.into()); | |
| } | |
| if line.is_empty() { | |
| return Err(SortError::ZeroLengthFileName { | |
| file: files0_from, | |
| line_num: line_num + 1, | |
| } | |
| .into()); | |
| } | |
| let filename = uucore::os_string_from_vec(line)?; | |
| files.push(filename); | |
| } |
| for (line_num, line) in buf_reader.split(b'\0').flatten().enumerate() { | ||
| let f = std::str::from_utf8(&line) | ||
| .expect("Could not parse string from zero terminated input."); | ||
| match f { | ||
| STDIN_FILE => { | ||
| return Err(SortError::MinusInStdIn.into()); | ||
| // Handle filenames as raw bytes to support non-UTF-8 paths | ||
| #[cfg(unix)] | ||
| let filename = { | ||
| use std::os::unix::ffi::OsStrExt; | ||
| OsStr::from_bytes(&line).to_owned() | ||
| }; | ||
| #[cfg(not(unix))] | ||
| let filename = { | ||
| // On non-Unix systems, convert to UTF-8 with replacement chars | ||
| match std::str::from_utf8(&line) { | ||
| Ok(s) => OsString::from(s), | ||
| Err(_) => OsString::from(String::from_utf8_lossy(&line).into_owned()), | ||
| } | ||
| "" => { | ||
| return Err(SortError::ZeroLengthFileName { | ||
| file: files0_from, | ||
| line_num: line_num + 1, | ||
| } | ||
| .into()); | ||
| }; | ||
|
|
||
| // Check for special cases using bytes comparison | ||
| if line == b"-" { | ||
| return Err(SortError::MinusInStdIn.into()); | ||
| } | ||
| if line.is_empty() { | ||
| return Err(SortError::ZeroLengthFileName { | ||
| file: files0_from, | ||
| line_num: line_num + 1, | ||
| } | ||
| _ => {} | ||
| .into()); | ||
| } | ||
|
|
||
| files.push(OsString::from( | ||
| std::str::from_utf8(&line) | ||
| .expect("Could not parse string from zero terminated input."), | ||
| )); | ||
| files.push(filename); | ||
| } |
There was a problem hiding this comment.
The platform-specific code can be simplified using the existing uucore::os_string_from_vec helper, I was testing this locally. The only thing that would be functionally different is that it would error instead of doing lossy string conversion on non-unix which is what is done in a bunch of other utilities
| for (line_num, line) in buf_reader.split(b'\0').flatten().enumerate() { | |
| let f = std::str::from_utf8(&line) | |
| .expect("Could not parse string from zero terminated input."); | |
| match f { | |
| STDIN_FILE => { | |
| return Err(SortError::MinusInStdIn.into()); | |
| // Handle filenames as raw bytes to support non-UTF-8 paths | |
| #[cfg(unix)] | |
| let filename = { | |
| use std::os::unix::ffi::OsStrExt; | |
| OsStr::from_bytes(&line).to_owned() | |
| }; | |
| #[cfg(not(unix))] | |
| let filename = { | |
| // On non-Unix systems, convert to UTF-8 with replacement chars | |
| match std::str::from_utf8(&line) { | |
| Ok(s) => OsString::from(s), | |
| Err(_) => OsString::from(String::from_utf8_lossy(&line).into_owned()), | |
| } | |
| "" => { | |
| return Err(SortError::ZeroLengthFileName { | |
| file: files0_from, | |
| line_num: line_num + 1, | |
| } | |
| .into()); | |
| }; | |
| // Check for special cases using bytes comparison | |
| if line == b"-" { | |
| return Err(SortError::MinusInStdIn.into()); | |
| } | |
| if line.is_empty() { | |
| return Err(SortError::ZeroLengthFileName { | |
| file: files0_from, | |
| line_num: line_num + 1, | |
| } | |
| _ => {} | |
| .into()); | |
| } | |
| files.push(OsString::from( | |
| std::str::from_utf8(&line) | |
| .expect("Could not parse string from zero terminated input."), | |
| )); | |
| files.push(filename); | |
| } | |
| for (line_num, line) in buf_reader.split(b'\0').flatten().enumerate() { | |
| // Check for special cases using bytes comparison | |
| if line == b"-" { | |
| return Err(SortError::MinusInStdIn.into()); | |
| } | |
| if line.is_empty() { | |
| return Err(SortError::ZeroLengthFileName { | |
| file: files0_from, | |
| line_num: line_num + 1, | |
| } | |
| .into()); | |
| } | |
| let filename = uucore::os_string_from_vec(line)?; | |
| files.push(filename); | |
| } |
|
GNU testsuite comparison: |
|
stuck, closing |
No description provided.