From: Bruno Haible Date: Sun, 18 May 2025 23:52:59 +0000 (+0200) Subject: unigbrk/u*-grapheme-breaks: Tiny optimization. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d37d77f6c9803541a9f773df29a4b90f65f4a4d;p=thirdparty%2Fgnulib.git unigbrk/u*-grapheme-breaks: Tiny optimization. * lib/unigbrk/u-grapheme-breaks.h (FUNC): Exploit the fact that n > 0. --- diff --git a/ChangeLog b/ChangeLog index 32a3bb93a3..f9eecbc588 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2025-05-18 Bruno Haible + + unigbrk/u*-grapheme-breaks: Tiny optimization. + * lib/unigbrk/u-grapheme-breaks.h (FUNC): Exploit the fact that n > 0. + 2025-05-17 Bruno Haible cosh: Add more tests. diff --git a/lib/unigbrk/u-grapheme-breaks.h b/lib/unigbrk/u-grapheme-breaks.h index 4066c9e6bb..30d5853a45 100644 --- a/lib/unigbrk/u-grapheme-breaks.h +++ b/lib/unigbrk/u-grapheme-breaks.h @@ -1,6 +1,5 @@ /* Grapheme cluster break function. Copyright (C) 2010-2025 Free Software Foundation, Inc. - Written by Ben Pfaff , 2010. This file is free software. It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+". @@ -23,6 +22,8 @@ License and of the GNU General Public License along with this program. If not, see . */ +/* Written by Ben Pfaff, Daiki Ueno, Bruno Haible. */ + /* This file implements section 3 "Grapheme Cluster Boundaries" of Unicode Standard Annex #29 . */ @@ -61,8 +62,9 @@ FUNC (const UNIT *s, size_t n, char *p) /* Don't break inside multibyte characters. */ memset (p, 0, n); - while (s < s_end) + do { + /* Invariant: Here s < s_end. */ ucs4_t uc; int count = U_MBTOUC (&uc, s, s_end - s); int prop = uc_graphemeclusterbreak_property (uc); @@ -157,5 +159,6 @@ FUNC (const UNIT *s, size_t n, char *p) s += count; p += count; } + while (s < s_end); } }