1 /* Copyright (C) 1996-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
19 #define _WEIGHTWC_H_ 1
21 #include <libc-diag.h>
23 /* Find index of weight. */
24 static inline int32_t __attribute__ ((always_inline
))
25 findidx (const int32_t *table
,
26 const int32_t *indirect
,
28 const wint_t **cpp
, size_t len
)
30 /* With GCC 7 when compiling with -Os the compiler warns that
31 seq1.back_us and seq2.back_us, which become *cpp, might be used
32 uninitialized. This is impossible as this function cannot be
33 called except in cases where those fields have been
35 DIAG_PUSH_NEEDS_COMMENT
;
36 DIAG_IGNORE_Os_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
37 wint_t ch
= *(*cpp
)++;
38 DIAG_POP_NEEDS_COMMENT
;
39 int32_t i
= __collidx_table_lookup ((const char *) table
, ch
);
42 /* This is an index into the weight table. Cool. */
45 /* Oh well, more than one sequence starting with this byte.
46 Search for the correct one. */
47 const int32_t *cp
= (const int32_t *) &extra
[-i
];
52 const int32_t *usrc
= (const int32_t *) *cpp
;
54 /* The first thing is the index. */
57 /* Next is the length of the byte sequence. These are always
58 short byte sequences so there is no reason to call any
59 function (even if they are inlined). */
64 /* It is a single character. If it matches we found our
65 index. Note that at the end of each list there is an
66 entry of length zero which represents the single byte
67 sequence. The first (and here only) byte was tested
71 /* With GCC 5.3 when compiling with -Os the compiler warns
72 that seq2.back_us, which becomes usrc, might be used
73 uninitialized. This can't be true because we pass a length
74 of -1 for len at the same time which means that this loop
76 DIAG_PUSH_NEEDS_COMMENT
;
77 DIAG_IGNORE_Os_NEEDS_COMMENT (5, "-Wmaybe-uninitialized");
78 for (cnt
= 0; cnt
< nhere
&& cnt
< len
; ++cnt
)
79 if (cp
[cnt
] != usrc
[cnt
])
81 DIAG_POP_NEEDS_COMMENT
;
90 /* Up to the next entry. */
95 /* This is a range of characters. First decide whether the
96 current byte sequence lies in the range. */
100 /* With GCC 7 when compiling with -Os the compiler warns
101 that seq1.back_us and seq2.back_us, which become usrc,
102 might be used uninitialized. This is impossible for the
103 same reason as described above. */
104 DIAG_PUSH_NEEDS_COMMENT
;
105 DIAG_IGNORE_Os_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
106 for (cnt
= 0; cnt
< nhere
- 1 && cnt
< len
; ++cnt
)
107 if (cp
[cnt
] != usrc
[cnt
])
109 DIAG_POP_NEEDS_COMMENT
;
111 if (cnt
< nhere
- 1 || cnt
== len
)
117 /* With GCC 7 when compiling with -Os the compiler warns
118 that seq1.back_us and seq2.back_us, which become usrc,
119 might be used uninitialized. This is impossible for the
120 same reason as described above. */
121 DIAG_PUSH_NEEDS_COMMENT
;
122 DIAG_IGNORE_Os_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
123 if (cp
[nhere
- 1] > usrc
[nhere
- 1])
128 DIAG_POP_NEEDS_COMMENT
;
130 if (cp
[2 * nhere
- 1] < usrc
[nhere
- 1])
136 /* This range matches the next characters. Now find
137 the offset in the indirect table. */
138 offset
= usrc
[nhere
- 1] - cp
[nhere
- 1];
141 return indirect
[-i
+ offset
];
149 #endif /* weightwc.h */