Repository navigation
sort: apply -d and -i to -V keys - #15650
ozenyunus35 wants to merge 3 commits into
Conversation
-V compared the raw key, so -d and -i were ignored, globally and per key. Remove the characters they ignore before comparing the key as a version. The filtered keys go into reused thread-local buffers, and a key is only copied when something is removed from it.
Merging this PR will degrade performance by 4.68%2 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
|
Binary size comparison: |
| .stdout_is("0.1\n0.02\n0.2\n0.002\n0.3\n"); | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
Could you use #[rstest] cases?
| } | ||
|
|
||
| // -d and -i drop characters from the key before it is compared as a version | ||
| #[rstest] |
There was a problem hiding this comment.
on second thoughts, would this better as four separate tests?
Fixes #15587
-Vcompared the raw key, so-dand-iwere ignored, both globally and per key (-k1dV). The-Vcomparison now removes the characters that-d/-iignore before comparing the key as a version. The check uses the samefilter_charas the other modes:filter_keyreturns the key itself when nothing needs removing. Otherwise it copies the kept bytes into a buffer. The two buffers are thread-local and reused, so a comparison doesn't allocate. Plain-Vdoesn't go through this path.I added
test_version_sort_dictionary_order_and_ignore_nonprinting(-dV,-k1dV,-k1,1dV,-iV,-c -iV). It fails without the change, and alltest_sortanduu_sorttests pass. Compared with GNU 9.12 (LC_ALL=C), 17 combinations on a 400-line file with punctuation, blanks, control and non-ASCII bytes give the same output:-V,-dV,-iV,-k1dV,-k1iV,-k1,1dV, with-s,-r,-u,-c,-b, and-t . -k2dV/-k2,2iV. On main, 5 of 6-d/-icases differed. Two combinations still differ, and other PRs cover them:-diVneeds-dto override-i(#15643), and-fdVneeds-Vto fold case (#15468).Timing with a release build,
--parallel=1, on a 500,000-line file of version strings (mean of 7 runs):sort -V: 1.03 s on main, 1.04 s heresort -iV: 1.05 s → 1.15 ssort -dV: 1.03 s → 1.24 sOn main,
-iVand-dVdidn't filter at all, so they cost the same as-V. My first version allocated a new key on each comparison, and-dVtook 1.89 s. With the reused buffers it is 1.24 s. The output on that file is the same as GNU's for-dVand-iV.I used an AI assistant to help draft parts of the code and tests; I reviewed the changes and ran the tests myself.