]> Savannah Git Hosting - gnulib.git/commitdiff
mbchar: Optimize all chars from the POSIX "portable character set".
authorBruno Haible <bruno@clisp.org>
Tue, 4 Jul 2023 13:31:09 +0000 (15:31 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 4 Jul 2023 13:31:09 +0000 (15:31 +0200)
* lib/mbchar.h (is_basic): Include all the characters from the POSIX
"portable character set".
* lib/mbchar.c (is_basic_table): Likewise.
* lib/mbiter.h (mbiter_multi_next): Update comment.
* lib/mbuiter.h (mbuiter_multi_next): Likewise.
* lib/mbfile.h (mbfile_multi_getc): Likewise.

ChangeLog
lib/mbchar.c
lib/mbchar.h
lib/mbfile.h
lib/mbiter.h
lib/mbuiter.h

index 38ef1b3b2d64caf1701bbfbfe45445aac32b3df0..c8709393b2b74e0c01072ef44af48d61f8839e67 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-07-04  Bruno Haible  <bruno@clisp.org>
+
+       mbchar: Optimize all chars from the POSIX "portable character set".
+       * lib/mbchar.h (is_basic): Include all the characters from the POSIX
+       "portable character set".
+       * lib/mbchar.c (is_basic_table): Likewise.
+       * lib/mbiter.h (mbiter_multi_next): Update comment.
+       * lib/mbuiter.h (mbuiter_multi_next): Likewise.
+       * lib/mbfile.h (mbfile_multi_getc): Likewise.
+
 2023-07-04  Paul Eggert  <eggert@cs.ucla.edu>
 
        mbchar: treat @, $, ` as basic
index 84b388bfee2905f26a6daa4742a308db72773643..63ff9c7a72523deee249cbe63b8c497ea7c12df6 100644 (file)
 
 #if IS_BASIC_ASCII
 
-/* Bit table of characters in the ISO C "basic character set",
-   plus the characters '@', '$', and '`' which
-   ISO C guarantees to be single-byte and in practice are safe
-   to treat as basic in the execution character set.  */
+/* Bit table of characters in the POSIX "portable character set", which
+   POSIX guarantees to be single-byte and in practice are safe to treat
+   like the ISO C "basic character set".  */
 const unsigned int is_basic_table [UCHAR_MAX / 32 + 1] =
 {
-  0x00001a00,           /* '\t' '\v' '\f' */
+  0x00003f81,           /* '\0' '\007' '\010' '\t' '\n' '\v' '\f' '\r' */
   0xffffffff,           /* ' '......'?' */
   0xffffffff,           /* '@' 'A'...'Z' '[' '\\' ']' '^' '_' */
   0x7fffffff            /* '`' 'a'...'z' '{' '|' '}' '~' */
index dea1e462eebb29917dd26992be54559768508634..36bae182763aba749539419e8b3d9907eb4770ea 100644 (file)
@@ -272,35 +272,40 @@ mb_copy (mbchar_t *new_mbc, const mbchar_t *old_mbc)
 }
 
 
-/* is_basic(c) tests whether the single-byte character c is in the
-   ISO C "basic character set" or is one of '@', '$', and '`' which
-   ISO C 23 § 5.2.1.1.(1) guarantees to be single-byte and in practice
-   are safe to treat as basic in the execution character set.
+/* is_basic(c) tests whether the single-byte character c is
+   - in the ISO C "basic character set" or is one of '@', '$', and '`'
+     which ISO C 23 § 5.2.1.1.(1) guarantees to be single-byte and in
+     practice are safe to treat as basic in the execution character set,
+     or
+   - in the POSIX "portable character set", which
+     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap06.html>
+     equally guarantees to be single-byte.
    This is a convenience function, and is in this file only to share code
-   between mbiter_multi.h and mbfile_multi.h.  */
-#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) && ('$' == 36) \
-    && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
-    && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
-    && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
-    && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
-    && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
-    && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
-    && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('@' == 64) && ('A' == 65) \
-    && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
-    && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
-    && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
-    && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
-    && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
-    && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
-    && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
-    && ('^' == 94) && ('_' == 95) && ('`' == 96) && ('a' == 97) && ('b' == 98) \
-    && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
-    && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
-    && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
-    && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
-    && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
-    && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
-    && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)
+   between mbiter.h, mbuiter.h, and mbfile.h.  */
+#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+    && ('$' == 36) && ('%' == 37) && ('&' == 38) && ('\'' == 39) \
+    && ('(' == 40) && (')' == 41) && ('*' == 42) && ('+' == 43) \
+    && (',' == 44) && ('-' == 45) && ('.' == 46) && ('/' == 47) \
+    && ('0' == 48) && ('1' == 49) && ('2' == 50) && ('3' == 51) \
+    && ('4' == 52) && ('5' == 53) && ('6' == 54) && ('7' == 55) \
+    && ('8' == 56) && ('9' == 57) && (':' == 58) && (';' == 59) \
+    && ('<' == 60) && ('=' == 61) && ('>' == 62) && ('?' == 63) \
+    && ('@' == 64) && ('A' == 65) && ('B' == 66) && ('C' == 67) \
+    && ('D' == 68) && ('E' == 69) && ('F' == 70) && ('G' == 71) \
+    && ('H' == 72) && ('I' == 73) && ('J' == 74) && ('K' == 75) \
+    && ('L' == 76) && ('M' == 77) && ('N' == 78) && ('O' == 79) \
+    && ('P' == 80) && ('Q' == 81) && ('R' == 82) && ('S' == 83) \
+    && ('T' == 84) && ('U' == 85) && ('V' == 86) && ('W' == 87) \
+    && ('X' == 88) && ('Y' == 89) && ('Z' == 90) && ('[' == 91) \
+    && ('\\' == 92) && (']' == 93) && ('^' == 94) && ('_' == 95) \
+    && ('`' == 96) && ('a' == 97) && ('b' == 98) && ('c' == 99) \
+    && ('d' == 100) && ('e' == 101) && ('f' == 102) && ('g' == 103) \
+    && ('h' == 104) && ('i' == 105) && ('j' == 106) && ('k' == 107) \
+    && ('l' == 108) && ('m' == 109) && ('n' == 110) && ('o' == 111) \
+    && ('p' == 112) && ('q' == 113) && ('r' == 114) && ('s' == 115) \
+    && ('t' == 116) && ('u' == 117) && ('v' == 118) && ('w' == 119) \
+    && ('x' == 120) && ('y' == 121) && ('z' == 122) && ('{' == 123) \
+    && ('|' == 124) && ('}' == 125) && ('~' == 126)
 /* The character set is ISO-646, not EBCDIC. */
 # define IS_BASIC_ASCII 1
 
@@ -320,7 +325,9 @@ is_basic (char c)
 {
   switch (c)
     {
-    case '\t': case '\v': case '\f':
+    case '\0':
+    case '\007': case '\010':
+    case '\t': case '\n': case '\v': case '\f': case '\r':
     case ' ': case '!': case '"': case '#': case '$': case '%':
     case '&': case '\'': case '(': case ')': case '*':
     case '+': case ',': case '-': case '.': case '/':
index 716ab3fc89d3e123586b5862b0118dc9004f66c0..9a2532992e9260005bbb85b9db260ffeec7a627b 100644 (file)
@@ -108,9 +108,12 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf)
   /* Handle most ASCII characters quickly, without calling mbrtowc().  */
   if (mbf->bufcount == 1 && mbsinit (&mbf->state) && is_basic (mbf->buf[0]))
     {
-      /* These characters are part of the basic character set.  ISO C 99
-         guarantees that their wide character code is identical to their
-         char code.  The 32-bit wide character code is the same as well.  */
+      /* These characters are part of the POSIX portable character set.
+         For most of them, namely those in the ISO C basic character set,
+         ISO C 99 guarantees that their wide character code is identical to
+         their char code.  For the few other ones, this is the case as well,
+         in all locale encodings that are in use.  The 32-bit wide character
+         code is the same as well.  */
       mbc->wc = mbc->buf[0] = mbf->buf[0];
       mbc->wc_valid = true;
       mbc->ptr = &mbc->buf[0];
index fadefe104bb76d0a8d47fa2ccd759a1e7edca747..bc88b4f3a20e7fd290b3ffc45fee9ac34a01be42 100644 (file)
@@ -124,9 +124,12 @@ mbiter_multi_next (struct mbiter_multi *iter)
   /* Handle most ASCII characters quickly, without calling mbrtowc().  */
   if (is_basic (*iter->cur.ptr))
     {
-      /* These characters are part of the basic character set.  ISO C 99
-         guarantees that their wide character code is identical to their
-         char code.  */
+      /* These characters are part of the POSIX portable character set.
+         For most of them, namely those in the ISO C basic character set,
+         ISO C 99 guarantees that their wide character code is identical to
+         their char code.  For the few other ones, this is the case as well,
+         in all locale encodings that are in use.  The 32-bit wide character
+         code is the same as well.  */
       iter->cur.bytes = 1;
       iter->cur.wc = *iter->cur.ptr;
       iter->cur.wc_valid = true;
index 954e11f6354995ab8e33f833caabfd983a3c72f6..93dec816038d4058c7b108915fe3472f1731b019 100644 (file)
@@ -132,9 +132,12 @@ mbuiter_multi_next (struct mbuiter_multi *iter)
   /* Handle most ASCII characters quickly, without calling mbrtowc().  */
   if (is_basic (*iter->cur.ptr))
     {
-      /* These characters are part of the basic character set.  ISO C 99
-         guarantees that their wide character code is identical to their
-         char code.  */
+      /* These characters are part of the POSIX portable character set.
+         For most of them, namely those in the ISO C basic character set,
+         ISO C 99 guarantees that their wide character code is identical to
+         their char code.  For the few other ones, this is the case as well,
+         in all locale encodings that are in use.  The 32-bit wide character
+         code is the same as well.  */
       iter->cur.bytes = 1;
       iter->cur.wc = *iter->cur.ptr;
       iter->cur.wc_valid = true;