1 /* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Ulrich Drepper, <drepper@cygnus.com>.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
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
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* Find index of weight. */
22 findidx (const unsigned char **cpp
)
24 int_fast32_t i
= table
[*(*cpp
)++];
25 const unsigned char *cp
;
26 const unsigned char *usrc
;
29 /* This is an index into the weight table. Cool. */
32 /* Oh well, more than one sequence starting with this byte.
33 Search for the correct one. */
40 /* The first thing is the index. */
41 i
= *((const int32_t *) cp
);
42 cp
+= sizeof (int32_t);
44 /* Next is the length of the byte sequence. These are always
45 short byte sequences so there is no reason to call any
46 function (even if they are inlined). */
51 /* It is a single character. If it matches we found our
52 index. Note that at the end of each list there is an
53 entry of length zero which represents the single byte
54 sequence. The first (and here only) byte was tested
58 for (cnt
= 0; cnt
< nhere
; ++cnt
)
59 if (cp
[cnt
] != usrc
[cnt
])
69 /* Up to the next entry. */
71 if ((1 + nhere
) % __alignof__ (int32_t) != 0)
72 cp
+= __alignof__ (int32_t) - (1 + nhere
) % __alignof__ (int32_t);
76 /* This is a range of characters. First decide whether the
77 current byte sequence lies in the range. */
81 for (cnt
= 0; cnt
< nhere
; ++cnt
)
82 if (cp
[cnt
] != usrc
[cnt
])
87 if (cp
[cnt
] > usrc
[cnt
])
89 /* Cannot be in this range. */
91 if ((1 + 2 * nhere
) % __alignof__ (int32_t) != 0)
92 cp
+= (__alignof__ (int32_t)
93 - (1 + 2 * nhere
) % __alignof__ (int32_t));
97 /* Test against the end of the range. */
98 for (cnt
= 0; cnt
< nhere
; ++cnt
)
99 if (cp
[nhere
+ cnt
] != usrc
[cnt
])
102 if (cnt
!= nhere
&& cp
[nhere
+ cnt
] < usrc
[cnt
])
104 /* Cannot be in this range. */
106 if ((1 + 2 * nhere
) % __alignof__ (int32_t) != 0)
107 cp
+= (__alignof__ (int32_t)
108 - (1 + 2 * nhere
) % __alignof__ (int32_t));
112 /* This range matches the next characters. Now find
113 the offset in the indirect table. */
114 for (cnt
= 0; cp
[cnt
] == usrc
[cnt
]; ++cnt
);
119 offset
+= usrc
[cnt
] - cp
[cnt
];
121 while (++cnt
< nhere
);
125 return indirect
[-i
+ offset
];