Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/harfbuzz-ng/src/hb-set-private.hh

Issue 10510004: Roll harfbuzz-ng 3b8fd9c48f4bde368bf2d465c148b9743a9216ee (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-set.cc ('k') | third_party/harfbuzz-ng/src/hb-shape.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright © 2012 Google, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
27 #ifndef HB_SET_PRIVATE_HH
28 #define HB_SET_PRIVATE_HH
29
30 #include "hb-private.hh"
31 #include "hb-set.h"
32 #include "hb-object-private.hh"
33
34
35 /* TODO Make this faster and memmory efficient. */
36
37 struct _hb_set_t
38 {
39 inline void init (void) {
40 clear ();
41 }
42 inline void fini (void) {
43 }
44 inline void clear (void) {
45 memset (elts, 0, sizeof elts);
46 }
47 inline bool empty (void) const {
48 for (unsigned int i = 0; i < ARRAY_LENGTH (elts); i++)
49 if (elts[i])
50 return false;
51 return true;
52 }
53 inline void add (hb_codepoint_t g)
54 {
55 if (unlikely (g == SENTINEL)) return;
56 if (unlikely (g > MAX_G)) return;
57 elt (g) |= mask (g);
58 }
59 inline void del (hb_codepoint_t g)
60 {
61 if (unlikely (g > MAX_G)) return;
62 elt (g) &= ~mask (g);
63 }
64 inline bool has (hb_codepoint_t g) const
65 {
66 if (unlikely (g > MAX_G)) return false;
67 return !!(elt (g) & mask (g));
68 }
69 inline bool intersects (hb_codepoint_t first,
70 hb_codepoint_t last) const
71 {
72 if (unlikely (first > MAX_G)) return false;
73 if (unlikely (last > MAX_G)) last = MAX_G;
74 unsigned int end = last + 1;
75 for (hb_codepoint_t i = first; i < end; i++)
76 if (has (i))
77 return true;
78 return false;
79 }
80 inline bool equal (const hb_set_t *other) const
81 {
82 for (unsigned int i = 0; i < ELTS; i++)
83 if (elts[i] != other->elts[i])
84 return false;
85 return true;
86 }
87 inline void set (const hb_set_t *other)
88 {
89 for (unsigned int i = 0; i < ELTS; i++)
90 elts[i] = other->elts[i];
91 }
92 inline void union_ (const hb_set_t *other)
93 {
94 for (unsigned int i = 0; i < ELTS; i++)
95 elts[i] |= other->elts[i];
96 }
97 inline void intersect (const hb_set_t *other)
98 {
99 for (unsigned int i = 0; i < ELTS; i++)
100 elts[i] &= other->elts[i];
101 }
102 inline void subtract (const hb_set_t *other)
103 {
104 for (unsigned int i = 0; i < ELTS; i++)
105 elts[i] &= ~other->elts[i];
106 }
107 inline void symmetric_difference (const hb_set_t *other)
108 {
109 for (unsigned int i = 0; i < ELTS; i++)
110 elts[i] ^= other->elts[i];
111 }
112 inline bool next (hb_codepoint_t *codepoint)
113 {
114 if (unlikely (*codepoint == SENTINEL)) {
115 hb_codepoint_t i = get_min ();
116 if (i != SENTINEL) {
117 *codepoint = i;
118 return true;
119 } else
120 return false;
121 }
122 for (hb_codepoint_t i = *codepoint + 1; i < MAX_G + 1; i++)
123 if (has (i)) {
124 *codepoint = i;
125 return true;
126 }
127 return false;
128 }
129 inline hb_codepoint_t get_min (void) const
130 {
131 for (unsigned int i = 0; i < ELTS; i++)
132 if (elts[i])
133 for (unsigned int j = 0; i < BITS; j++)
134 if (elts[i] & (1 << j))
135 return i * BITS + j;
136 return SENTINEL;
137 }
138 inline hb_codepoint_t get_max (void) const
139 {
140 for (unsigned int i = ELTS; i; i--)
141 if (elts[i - 1])
142 for (unsigned int j = BITS; j; j--)
143 if (elts[i - 1] & (1 << (j - 1)))
144 return (i - 1) * BITS + (j - 1);
145 return SENTINEL;
146 }
147
148 typedef uint32_t elt_t;
149 static const unsigned int MAX_G = 65536 - 1; /* XXX Fix this... */
150 static const unsigned int SHIFT = 5;
151 static const unsigned int BITS = (1 << SHIFT);
152 static const unsigned int MASK = BITS - 1;
153 static const unsigned int ELTS = (MAX_G + 1 + (BITS - 1)) / BITS;
154 static const hb_codepoint_t SENTINEL = (hb_codepoint_t) -1;
155
156 elt_t &elt (hb_codepoint_t g) { return elts[g >> SHIFT]; }
157 elt_t elt (hb_codepoint_t g) const { return elts[g >> SHIFT]; }
158 elt_t mask (hb_codepoint_t g) const { return elt_t (1) << (g & MASK); }
159
160 hb_object_header_t header;
161 elt_t elts[ELTS]; /* XXX 8kb */
162
163 ASSERT_STATIC (sizeof (elt_t) * 8 == BITS);
164 ASSERT_STATIC (sizeof (elt_t) * 8 * ELTS > MAX_G);
165 };
166
167
168
169 #endif /* HB_SET_PRIVATE_HH */
OLDNEW
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-set.cc ('k') | third_party/harfbuzz-ng/src/hb-shape.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698