Repository navigation
rev: reverse by character in UTF-8 locales - #657
Open
SichenLiang wants to merge 1 commit into
Open
SichenLiang wants to merge 1 commit into
SichenLiang wants to merge 1 commit into
Conversation
When the first nonempty value of LC_ALL, LC_CTYPE and LANG names a UTF-8 codeset, reverse valid UTF-8 records by code point. Keep byte reversal in other locales and for records that are not valid UTF-8.
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.
In a UTF-8 locale, reverse valid UTF-8 records by code point instead of by byte. Other locales keep the existing byte-reversal behavior.
The locale is taken from the first nonempty value of
LC_ALL,LC_CTYPE, andLANG. The manual now documents that rule.Records that are not valid UTF-8 are still reversed byte by byte and exit 0; util-linux reports an
fgetwc()error instead.On an x86_64 Linux machine, 64 MiB of records made entirely of multibyte characters took 5.9 to 7.2 times as much CPU as main, depending on code alignment, because they are now validated and reversed on character boundaries. Long ASCII records in a UTF-8 locale were 13% to 22% faster. In the C locale the code path is unchanged; a 7% difference there went away when both binaries were rebuilt with branch alignment. Short ASCII lines were about 3% slower.
Tests cover locale precedence, valid and invalid records, files, NUL-delimited input, and long records.
Fixes #656