Improve GNU compatibility through byte processing#487
Conversation
|
GNU sed testsuite comparison: |
9258d95 to
39f18c2
Compare
|
GNU sed testsuite comparison: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #487 +/- ##
==========================================
+ Coverage 83.05% 84.98% +1.92%
==========================================
Files 13 13
Lines 6120 6760 +640
Branches 358 378 +20
==========================================
+ Hits 5083 5745 +662
+ Misses 1034 1012 -22
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 18.22%
Performance Changes
Tip Curious why this is faster? Comment Comparing |
39f18c2 to
60aa15b
Compare
|
GNU sed testsuite comparison: |
60aa15b to
58f773c
Compare
|
GNU sed testsuite comparison: |
There was a problem hiding this comment.
Pull request overview
This PR refactors the sed implementation to improve GNU sed compatibility and binary-file handling by switching most internal processing from Rust String/Unicode semantics to byte-oriented (Vec<u8>) semantics, while still enabling UTF-8-aware behavior when the environment locale indicates it.
Changes:
- Introduces locale-driven
CharacterMode(byte vs UTF-8) and updates processing paths accordingly (regex, transliteration, list output, and script parsing). - Migrates key data structures (pattern/hold space, script providers, writers, output buffering) to operate on bytes instead of UTF-8 strings.
- Expands/adjusts integration and unit tests to explicitly cover both byte-mode (
LC_ALL=C) and UTF-8-mode (LC_ALL=C.UTF-8) behavior, including invalid UTF-8 cases.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/tests.rs | Sets default test locale to UTF-8 to keep fixture-based tests stable while allowing explicit byte-mode overrides. |
| tests/by-util/test_sed.rs | Adds/updates locale-explicit tests and extends coverage for byte/UTF-8 mode differences (backrefs, escapes, listing, transliteration). |
| src/sed/script_line_provider.rs | Returns raw script lines as bytes and preserves invalid UTF-8 from file sources. |
| src/sed/script_char_provider.rs | Switches script scanning from chars to bytes; adds APIs for raw byte access. |
| src/sed/processor.rs | Updates core processing to use byte pattern spaces; adds byte/UTF-8 aware list and transliteration paths. |
| src/sed/named_writer.rs | Adds byte-writing support for w-style outputs to preserve arbitrary bytes. |
| src/sed/mod.rs | Adds locale parsing and initializes ProcessingContext with environment-derived CharacterMode. |
| src/sed/fast_regex.rs | Reworks regex abstraction to accept byte patterns, support byte-mode restrictions, and return matches as bytes. |
| src/sed/fast_io.rs | Converts IO chunk storage and output scheduling to bytes; updates readers/writers to avoid UTF-8 assumptions. |
| src/sed/delimited_parser.rs | Parses delimited constructs into bytes, adds byte→OsString conversion utility, and introduces mode-aware parsing helpers. |
| src/sed/compiler.rs | Compiles regex/transliteration/replacements in a character-mode-aware way and switches script file paths to byte-safe handling. |
| src/sed/command.rs | Introduces CharacterMode, migrates replacement/template handling to bytes, and extends transliteration for byte and UTF-8 modes. |
| README.md | Documents new locale-driven behavior, limitations vs GNU sed locales, and byte-mode backref restriction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
GNU sed testsuite comparison: |
ef35132 to
431c083
Compare
|
GNU sed testsuite comparison: |
The original Rust implementation assummed a UTF-8 environment, as is common in modern systems. This commit improves GNU sed compatibility by changing most processing to run on bytes rather than Rust's Unicode characters and strings. This change also improves the handling of binary files. The commit adds a simple POSIX-compatible locale configuration to support UTF-8 processing when specified. While at it, also fix script-specified file handling to take place through OsString and add a few missing unit tests. The change fixes two failing GNU test suite cases.
431c083 to
c58cecc
Compare
|
GNU sed testsuite comparison: |
|
I force-pushed a few unit tests to also pass |
The original Rust implementation assummed a UTF-8 environment, as is common in modern systems. This commit improves GNU sed compatibility by changing most processing to run on bytes rather than Rust's Unicode characters and strings. This change also improves the handling of binary files. The commit adds a simple POSIX-compatible locale configuration to support UTF-8 processing when specified. While at it, also fix script-specified file handling to take place through OsString.
The change fixes two failing GNU test suite cases.