OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2012 Google, Inc. | 2 * Copyright © 2012 Google, Inc. |
3 * | 3 * |
4 * This is part of HarfBuzz, a text shaping library. | 4 * This is part of HarfBuzz, a text shaping library. |
5 * | 5 * |
6 * Permission is hereby granted, without written agreement and without | 6 * Permission is hereby granted, without written agreement and without |
7 * license or royalty fees, to use, copy, modify, and distribute this | 7 * license or royalty fees, to use, copy, modify, and distribute this |
8 * software and its documentation for any purpose, provided that the | 8 * software and its documentation for any purpose, provided that the |
9 * above copyright notice and the following two paragraphs appear in | 9 * above copyright notice and the following two paragraphs appear in |
10 * all copies of this software. | 10 * all copies of this software. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 inline bool is_empty (void) const { | 165 inline bool is_empty (void) const { |
166 for (unsigned int i = 0; i < ARRAY_LENGTH (elts); i++) | 166 for (unsigned int i = 0; i < ARRAY_LENGTH (elts); i++) |
167 if (elts[i]) | 167 if (elts[i]) |
168 return false; | 168 return false; |
169 return true; | 169 return true; |
170 } | 170 } |
171 inline void add (hb_codepoint_t g) | 171 inline void add (hb_codepoint_t g) |
172 { | 172 { |
173 if (unlikely (in_error)) return; | 173 if (unlikely (in_error)) return; |
174 if (unlikely (g == SENTINEL)) return; | 174 if (unlikely (g == INVALID)) return; |
175 if (unlikely (g > MAX_G)) return; | 175 if (unlikely (g > MAX_G)) return; |
176 elt (g) |= mask (g); | 176 elt (g) |= mask (g); |
177 } | 177 } |
178 inline void add_range (hb_codepoint_t a, hb_codepoint_t b) | 178 inline void add_range (hb_codepoint_t a, hb_codepoint_t b) |
179 { | 179 { |
180 if (unlikely (in_error)) return; | 180 if (unlikely (in_error)) return; |
181 /* TODO Speedup */ | 181 /* TODO Speedup */ |
182 for (unsigned int i = a; i < b + 1; i++) | 182 for (unsigned int i = a; i < b + 1; i++) |
183 add (i); | 183 add (i); |
184 } | 184 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 elts[i] ^= other->elts[i]; | 249 elts[i] ^= other->elts[i]; |
250 } | 250 } |
251 inline void invert (void) | 251 inline void invert (void) |
252 { | 252 { |
253 if (unlikely (in_error)) return; | 253 if (unlikely (in_error)) return; |
254 for (unsigned int i = 0; i < ELTS; i++) | 254 for (unsigned int i = 0; i < ELTS; i++) |
255 elts[i] = ~elts[i]; | 255 elts[i] = ~elts[i]; |
256 } | 256 } |
257 inline bool next (hb_codepoint_t *codepoint) const | 257 inline bool next (hb_codepoint_t *codepoint) const |
258 { | 258 { |
259 if (unlikely (*codepoint == SENTINEL)) { | 259 if (unlikely (*codepoint == INVALID)) { |
260 hb_codepoint_t i = get_min (); | 260 hb_codepoint_t i = get_min (); |
261 if (i != SENTINEL) { | 261 if (i != INVALID) { |
262 *codepoint = i; | 262 *codepoint = i; |
263 return true; | 263 return true; |
264 } else | 264 } else { |
| 265 » *codepoint = INVALID; |
265 return false; | 266 return false; |
| 267 } |
266 } | 268 } |
267 for (hb_codepoint_t i = *codepoint + 1; i < MAX_G + 1; i++) | 269 for (hb_codepoint_t i = *codepoint + 1; i < MAX_G + 1; i++) |
268 if (has (i)) { | 270 if (has (i)) { |
269 *codepoint = i; | 271 *codepoint = i; |
270 return true; | 272 return true; |
271 } | 273 } |
| 274 *codepoint = INVALID; |
272 return false; | 275 return false; |
273 } | 276 } |
274 inline bool next_range (hb_codepoint_t *first, hb_codepoint_t *last) const | 277 inline bool next_range (hb_codepoint_t *first, hb_codepoint_t *last) const |
275 { | 278 { |
276 hb_codepoint_t i; | 279 hb_codepoint_t i; |
277 | 280 |
278 i = *last; | 281 i = *last; |
279 if (!next (&i)) | 282 if (!next (&i)) |
| 283 { |
| 284 *last = *first = INVALID; |
280 return false; | 285 return false; |
| 286 } |
281 | 287 |
282 *last = *first = i; | 288 *last = *first = i; |
283 while (next (&i) && i == *last + 1) | 289 while (next (&i) && i == *last + 1) |
284 (*last)++; | 290 (*last)++; |
285 | 291 |
286 return true; | 292 return true; |
287 } | 293 } |
288 | 294 |
289 inline unsigned int get_population (void) const | 295 inline unsigned int get_population (void) const |
290 { | 296 { |
291 unsigned int count = 0; | 297 unsigned int count = 0; |
292 for (unsigned int i = 0; i < ELTS; i++) | 298 for (unsigned int i = 0; i < ELTS; i++) |
293 count += _hb_popcount32 (elts[i]); | 299 count += _hb_popcount32 (elts[i]); |
294 return count; | 300 return count; |
295 } | 301 } |
296 inline hb_codepoint_t get_min (void) const | 302 inline hb_codepoint_t get_min (void) const |
297 { | 303 { |
298 for (unsigned int i = 0; i < ELTS; i++) | 304 for (unsigned int i = 0; i < ELTS; i++) |
299 if (elts[i]) | 305 if (elts[i]) |
300 for (unsigned int j = 0; j < BITS; j++) | 306 for (unsigned int j = 0; j < BITS; j++) |
301 if (elts[i] & (1 << j)) | 307 if (elts[i] & (1 << j)) |
302 return i * BITS + j; | 308 return i * BITS + j; |
303 return SENTINEL; | 309 return INVALID; |
304 } | 310 } |
305 inline hb_codepoint_t get_max (void) const | 311 inline hb_codepoint_t get_max (void) const |
306 { | 312 { |
307 for (unsigned int i = ELTS; i; i--) | 313 for (unsigned int i = ELTS; i; i--) |
308 if (elts[i - 1]) | 314 if (elts[i - 1]) |
309 for (unsigned int j = BITS; j; j--) | 315 for (unsigned int j = BITS; j; j--) |
310 if (elts[i - 1] & (1 << (j - 1))) | 316 if (elts[i - 1] & (1 << (j - 1))) |
311 return (i - 1) * BITS + (j - 1); | 317 return (i - 1) * BITS + (j - 1); |
312 return SENTINEL; | 318 return INVALID; |
313 } | 319 } |
314 | 320 |
315 typedef uint32_t elt_t; | 321 typedef uint32_t elt_t; |
316 static const unsigned int MAX_G = 65536 - 1; /* XXX Fix this... */ | 322 static const unsigned int MAX_G = 65536 - 1; /* XXX Fix this... */ |
317 static const unsigned int SHIFT = 5; | 323 static const unsigned int SHIFT = 5; |
318 static const unsigned int BITS = (1 << SHIFT); | 324 static const unsigned int BITS = (1 << SHIFT); |
319 static const unsigned int MASK = BITS - 1; | 325 static const unsigned int MASK = BITS - 1; |
320 static const unsigned int ELTS = (MAX_G + 1 + (BITS - 1)) / BITS; | 326 static const unsigned int ELTS = (MAX_G + 1 + (BITS - 1)) / BITS; |
321 static const hb_codepoint_t SENTINEL = (hb_codepoint_t) -1; | 327 static const hb_codepoint_t INVALID = HB_SET_VALUE_INVALID; |
322 | 328 |
323 elt_t &elt (hb_codepoint_t g) { return elts[g >> SHIFT]; } | 329 elt_t &elt (hb_codepoint_t g) { return elts[g >> SHIFT]; } |
324 elt_t elt (hb_codepoint_t g) const { return elts[g >> SHIFT]; } | 330 elt_t elt (hb_codepoint_t g) const { return elts[g >> SHIFT]; } |
325 elt_t mask (hb_codepoint_t g) const { return elt_t (1) << (g & MASK); } | 331 elt_t mask (hb_codepoint_t g) const { return elt_t (1) << (g & MASK); } |
326 | 332 |
327 elt_t elts[ELTS]; /* XXX 8kb */ | 333 elt_t elts[ELTS]; /* XXX 8kb */ |
328 | 334 |
329 ASSERT_STATIC (sizeof (elt_t) * 8 == BITS); | 335 ASSERT_STATIC (sizeof (elt_t) * 8 == BITS); |
330 ASSERT_STATIC (sizeof (elt_t) * 8 * ELTS > MAX_G); | 336 ASSERT_STATIC (sizeof (elt_t) * 8 * ELTS > MAX_G); |
331 }; | 337 }; |
332 | 338 |
333 | 339 |
334 | 340 |
335 #endif /* HB_SET_PRIVATE_HH */ | 341 #endif /* HB_SET_PRIVATE_HH */ |
OLD | NEW |