1 /* Copyright (C) 1996-2024 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/>. */
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
,
27 const unsigned char *extra
,
28 const unsigned char **cpp
, size_t len
)
30 /* With GCC 8 when compiling with -Os the compiler warns that
31 seq1.back_us and seq2.back_us might be used uninitialized.
32 This uninitialized use is impossible for the same reason
33 as described in comments in locale/weightwc.h. */
34 DIAG_PUSH_NEEDS_COMMENT
;
35 DIAG_IGNORE_Os_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
36 int32_t i
= table
[*(*cpp
)++];
37 DIAG_POP_NEEDS_COMMENT
;
38 const unsigned char *cp
;
39 const unsigned char *usrc
;
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. */
54 /* The first thing is the index. */
55 i
= *((const int32_t *) cp
);
56 cp
+= sizeof (int32_t);
58 /* Next is the length of the byte sequence. These are always
59 short byte sequences so there is no reason to call any
60 function (even if they are inlined). */
65 /* It is a single character. If it matches we found our
66 index. Note that at the end of each list there is an
67 entry of length zero which represents the single byte
68 sequence. The first (and here only) byte was tested
72 /* With GCC 5.3 when compiling with -Os the compiler warns
73 that seq2.back_us, which becomes usrc, might be used
74 uninitialized. This can't be true because we pass a length
75 of -1 for len at the same time which means that this loop
77 DIAG_PUSH_NEEDS_COMMENT
;
78 DIAG_IGNORE_Os_NEEDS_COMMENT (5, "-Wmaybe-uninitialized");
79 for (cnt
= 0; cnt
< nhere
&& cnt
< len
; ++cnt
)
80 if (cp
[cnt
] != usrc
[cnt
])
82 DIAG_POP_NEEDS_COMMENT
;
91 /* Up to the next entry. */
93 if (!LOCFILE_ALIGNED_P (1 + nhere
))
94 cp
+= LOCFILE_ALIGN
- (1 + nhere
) % LOCFILE_ALIGN
;
98 /* This is a range of characters. First decide whether the
99 current byte sequence lies in the range. */
103 for (cnt
= 0; cnt
< nhere
&& cnt
< len
; ++cnt
)
104 if (cp
[cnt
] != usrc
[cnt
])
109 if (cnt
== len
|| cp
[cnt
] > usrc
[cnt
])
111 /* Cannot be in this range. */
113 if (!LOCFILE_ALIGNED_P (1 + 2 * nhere
))
115 - (1 + 2 * nhere
) % LOCFILE_ALIGN
);
119 /* Test against the end of the range. */
120 for (cnt
= 0; cnt
< nhere
; ++cnt
)
121 if (cp
[nhere
+ cnt
] != usrc
[cnt
])
124 if (cnt
!= nhere
&& cp
[nhere
+ cnt
] < usrc
[cnt
])
126 /* Cannot be in this range. */
128 if (!LOCFILE_ALIGNED_P (1 + 2 * nhere
))
130 - (1 + 2 * nhere
) % LOCFILE_ALIGN
);
134 /* This range matches the next characters. Now find
135 the offset in the indirect table. */
136 for (cnt
= 0; cp
[cnt
] == usrc
[cnt
]; ++cnt
);
141 /* With GCC 7 when compiling with -Os the compiler
142 warns that seq1.back_us and seq2.back_us, which
143 become usrc, might be used uninitialized. This
144 is impossible for the same reason as described
146 DIAG_PUSH_NEEDS_COMMENT
;
147 DIAG_IGNORE_Os_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
148 offset
+= usrc
[cnt
] - cp
[cnt
];
149 DIAG_POP_NEEDS_COMMENT
;
151 while (++cnt
< nhere
);
155 return indirect
[-i
+ offset
];
163 #endif /* weight.h */