comm: compare lines with the locale collation - #14047
Open
luantaraschi wants to merge 1 commit into
Open
Conversation
sort orders lines with the locale collation, and comm read that order back with a byte comparison. In a UTF-8 locale where the two disagree, comm rejected a file sort had just produced and put lines in the wrong column: comm -12 dropped the line the two files share, comm -23 reported a shared line as unique, and the exit code was 1 where GNU gives 0. sort, join, ls and expr already compare through uucore::i18n::collator. join has the same order check and reads this input correctly, so comm now uses the same comparison. In the C locale the lines are still compared as bytes.
|
Binary size comparison: |
|
GNU testsuite comparison: |
Merging this PR will improve performance by 4.14%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | cksum_crc32b |
40.3 ms | 38.7 ms | +4.14% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing luantaraschi:fix/comm-locale-collation (cec5ab2) with main (0ecfd3b)
Footnotes
-
50 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sortorders lines with the locale collation andcommreads that order backwith a byte comparison. In a UTF-8 locale where the two disagree,
commrejectsa file
sorthas just produced and puts lines in the wrong column.With
LC_ALL=en_US.UTF-8,f1holdinga1thena-b, which is the ordersortgives, andf2holdinga-b:comm -12 f1 f2a-ba-bcomm -13 f1 f2a-b, a line that is in both filescomm -23 f1 f2a1a1anda-ba1sort,join,lsandexpralready go throughuucore::i18n::collator, andjoin, which has the same order check, reads this input correctly today. Thisgives
commthe same comparison. In the C locale the lines are still comparedas bytes, so nothing changes there.
#12280 also touches
OrderChecker, but for a different thing: it changes whenthe warning is printed, not how the order is measured.
Fixes #12912
#12972 was closed as a duplicate of that one. It is an AOSP build failing after
45 minutes with
comm: file 1 is not in sorted order.