From 72e357240fac86530a9b9fdfad56c0a1619c7b5b Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 30 Dec 2019 23:23:42 -0800 Subject: [PATCH] localeinfo: ->simple would be wrong for LC_ALL=C That would lead to using unnecessary and expensive code paths in dfa.c. * lib/localeinfo.c (using_simple_locale): Fix recently-introduced logic error that would have made grep many times slower in the C locale. With this change, and a file created like this: yes 00 | head -10000000 > in Running grep as follows becomes more than 40 times faster: LC_ALL=C grep -Fw 0 in --- ChangeLog | 11 +++++++++++ lib/localeinfo.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index dccdf7a1a9..6f6e6190ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2019-12-30 Jim Meyering + + localeinfo: ->simple would be wrong for LC_ALL=C + That would lead to using unnecessary and expensive code paths in dfa.c. + * lib/localeinfo.c (using_simple_locale): Fix recently-introduced logic + error that would have made grep many times slower in the C locale. + With this change, and a file created like this: + yes 00 | head -10000000 > in + Running grep as follows becomes more than 40 times faster: + LC_ALL=C grep -Fw 0 in + 2019-12-30 Paul Eggert doc: document trouble with back-references diff --git a/lib/localeinfo.c b/lib/localeinfo.c index 372530e014..c22aca21f2 100644 --- a/lib/localeinfo.c +++ b/lib/localeinfo.c @@ -77,7 +77,7 @@ using_simple_locale (bool multibyte) where the native order is the collating-sequence order but there are multi-character collating elements. */ for (int i = 0; i < UCHAR_MAX; i++) - if (strcoll (((char []) {i, 0}), ((char []) {i + 1, 0})) <= 0) + if (0 <= strcoll (((char []) {i, 0}), ((char []) {i + 1, 0}))) return false; return true; -- 2.39.5