]> sourceware.org Git - glibc.git/blame - locale/weight.h
Handle EAGAIN from FUTEX_WAIT_REQUEUE_PI
[glibc.git] / locale / weight.h
CommitLineData
7090d3ca 1/* Copyright (C) 1996,1997,1998,1999,2000,2003,2004 Free Software Foundation, Inc.
6d52618b 2 This file is part of the GNU C Library.
5d08d218 3 Written by Ulrich Drepper, <drepper@cygnus.com>.
19bc17a9 4
6d52618b 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
19bc17a9 9
6d52618b
UD
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
19bc17a9 14
41bdb6e2
AJ
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19bc17a9 19
450bf66e 20/* Find index of weight. */
7090d3ca 21auto inline int32_t
dd9423a6 22__attribute ((always_inline))
450bf66e
UD
23findidx (const unsigned char **cpp)
24{
25 int_fast32_t i = table[*(*cpp)++];
26 const unsigned char *cp;
dbfdf944 27 const unsigned char *usrc;
19bc17a9 28
450bf66e
UD
29 if (i >= 0)
30 /* This is an index into the weight table. Cool. */
31 return i;
19bc17a9 32
450bf66e
UD
33 /* Oh well, more than one sequence starting with this byte.
34 Search for the correct one. */
35 cp = &extra[-i];
dbfdf944 36 usrc = *cpp;
450bf66e 37 while (1)
0393dfd6 38 {
450bf66e 39 size_t nhere;
19bc17a9 40
450bf66e 41 /* The first thing is the index. */
8b6e6767 42 i = *((const int32_t *) cp);
450bf66e 43 cp += sizeof (int32_t);
19bc17a9 44
450bf66e
UD
45 /* Next is the length of the byte sequence. These are always
46 short byte sequences so there is no reason to call any
47 function (even if they are inlined). */
48 nhere = *cp++;
19bc17a9 49
450bf66e 50 if (i >= 0)
19bc17a9 51 {
450bf66e
UD
52 /* It is a single character. If it matches we found our
53 index. Note that at the end of each list there is an
54 entry of length zero which represents the single byte
55 sequence. The first (and here only) byte was tested
56 already. */
57 size_t cnt;
19bc17a9 58
450bf66e
UD
59 for (cnt = 0; cnt < nhere; ++cnt)
60 if (cp[cnt] != usrc[cnt])
61 break;
19bc17a9 62
450bf66e
UD
63 if (cnt == nhere)
64 {
65 /* Found it. */
66 *cpp += nhere;
67 return i;
68 }
19bc17a9 69
450bf66e
UD
70 /* Up to the next entry. */
71 cp += nhere;
ee00109c
UD
72 if ((1 + nhere) % __alignof__ (int32_t) != 0)
73 cp += __alignof__ (int32_t) - (1 + nhere) % __alignof__ (int32_t);
19bc17a9 74 }
450bf66e
UD
75 else
76 {
77 /* This is a range of characters. First decide whether the
78 current byte sequence lies in the range. */
79 size_t cnt;
80 size_t offset = 0;
19bc17a9 81
450bf66e
UD
82 for (cnt = 0; cnt < nhere; ++cnt)
83 if (cp[cnt] != usrc[cnt])
84 break;
19bc17a9 85
450bf66e
UD
86 if (cnt != nhere)
87 {
88 if (cp[cnt] > usrc[cnt])
89 {
90 /* Cannot be in this range. */
91 cp += 2 * nhere;
ee00109c
UD
92 if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
93 cp += (__alignof__ (int32_t)
94 - (1 + 2 * nhere) % __alignof__ (int32_t));
450bf66e
UD
95 continue;
96 }
19bc17a9 97
450bf66e
UD
98 /* Test against the end of the range. */
99 for (cnt = 0; cnt < nhere; ++cnt)
100 if (cp[nhere + cnt] != usrc[cnt])
101 break;
19bc17a9 102
450bf66e
UD
103 if (cnt != nhere && cp[nhere + cnt] < usrc[cnt])
104 {
105 /* Cannot be in this range. */
106 cp += 2 * nhere;
ee00109c
UD
107 if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
108 cp += (__alignof__ (int32_t)
109 - (1 + 2 * nhere) % __alignof__ (int32_t));
450bf66e
UD
110 continue;
111 }
19bc17a9 112
450bf66e
UD
113 /* This range matches the next characters. Now find
114 the offset in the indirect table. */
115 for (cnt = 0; cp[cnt] == usrc[cnt]; ++cnt);
116
117 do
118 {
119 offset <<= 8;
120 offset += usrc[cnt] - cp[cnt];
121 }
122 while (++cnt < nhere);
19bc17a9 123 }
19bc17a9 124
450bf66e 125 *cpp += nhere;
dbfdf944 126 return indirect[-i + offset];
450bf66e 127 }
19bc17a9 128 }
19bc17a9 129
450bf66e
UD
130 /* NOTREACHED */
131 return 0x43219876;
132}
This page took 0.353012 seconds and 5 git commands to generate.