Skip to content

Commit d9cd766

Browse files
committed
engine_xetex: tidy up the stringpool functions a bit
1 parent 70b7570 commit d9cd766

1 file changed

Lines changed: 64 additions & 47 deletions

File tree

crates/engine_xetex/xetex/xetex-stringpool.c

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,151 +39,168 @@ load_pool_strings(int32_t spare_size)
3939
}
4040

4141

42-
43-
int32_t length(str_number s)
42+
int32_t
43+
length(str_number s)
4444
{
45-
if ((s >= 65536L))
46-
return str_start[(s + 1) - 65536L] - str_start[(s) - 65536L];
47-
else if ((s >= 32) && (s < 127))
45+
if (s >= 65536L)
46+
return str_start[s + 1 - 65536L] - str_start[s - 65536L];
47+
if (s >= 32 && s < 127)
4848
return 1;
49-
else if ((s <= 127))
49+
if (s <= 127)
5050
return 3;
51-
else if ((s < 256))
51+
if (s < 256)
5252
return 4;
53-
else
54-
return 8;
53+
return 8;
5554
}
5655

57-
str_number make_string(void)
56+
57+
str_number
58+
make_string(void)
5859
{
5960
if (str_ptr == max_strings)
6061
overflow("number of strings", max_strings - init_str_ptr);
62+
6163
str_ptr++;
6264
str_start[str_ptr - TOO_BIG_CHAR] = pool_ptr;
6365
return str_ptr - 1;
6466
}
6567

66-
void append_str(str_number s)
68+
69+
void
70+
append_str(str_number s)
6771
{
6872
int32_t i;
6973
pool_pointer j;
74+
7075
i = length(s);
71-
{
72-
if (pool_ptr + i > pool_size)
73-
overflow("pool size", pool_size - init_pool_ptr);
74-
}
75-
j = str_start[(s) - 65536L];
76-
while ((i > 0)) {
7776

78-
{
79-
str_pool[pool_ptr] = str_pool[j];
80-
pool_ptr++;
81-
}
77+
if (pool_ptr + i > pool_size)
78+
overflow("pool size", pool_size - init_pool_ptr);
79+
80+
j = str_start[s - 65536L];
81+
82+
while (i > 0) {
83+
str_pool[pool_ptr] = str_pool[j];
84+
pool_ptr++;
8285
j++;
8386
i--;
8487
}
8588
}
8689

87-
bool str_eq_buf(str_number s, int32_t k)
90+
91+
bool
92+
str_eq_buf(str_number s, int32_t k)
8893
{
8994
pool_pointer j;
90-
j = str_start[(s) - 65536L];
91-
while (j < str_start[(s + 1) - 65536L]) {
9295

93-
if (buffer[k] >= 65536L) {
96+
j = str_start[s - 65536L];
9497

98+
while (j < str_start[s + 1 - 65536L]) {
99+
if (buffer[k] >= 65536L) {
95100
if (str_pool[j] != 55296L + (buffer[k] - 65536L) / 1024) {
96101
return false;
97102
} else if (str_pool[j + 1] != 56320L + (buffer[k] - 65536L) % 1024) {
98103
return false;
99-
} else
104+
} else {
100105
j++;
106+
}
101107
} else if (str_pool[j] != buffer[k]) {
102108
return false;
103109
}
110+
104111
j++;
105112
k++;
106113
}
114+
107115
return true;
108116
}
109117

110-
bool str_eq_str(str_number s, str_number t)
118+
119+
bool
120+
str_eq_str(str_number s, str_number t)
111121
{
112122
pool_pointer j, k;
123+
113124
if (length(s) != length(t))
114125
return false;
115-
if ((length(s) == 1)) {
126+
127+
if (length(s) == 1) {
116128
if (s < 65536L) {
117129
if (t < 65536L) {
118130
if (s != t)
119131
return false;
120132
} else {
121-
122-
if (s != str_pool[str_start[(t) - 65536L]])
133+
if (s != str_pool[str_start[t - 65536L]])
123134
return false;
124135
}
125136
} else {
126-
127137
if (t < 65536L) {
128-
if (str_pool[str_start[(s) - 65536L]] != t)
138+
if (str_pool[str_start[s - 65536L]] != t)
129139
return false;
130140
} else {
131-
132-
if (str_pool[str_start[(s) - 65536L]] != str_pool[str_start[(t) - 65536L]])
141+
if (str_pool[str_start[s - 65536L]] != str_pool[str_start[t - 65536L]])
133142
return false;
134143
}
135144
}
136145
} else {
146+
j = str_start[s - 65536L];
147+
k = str_start[t - 65536L];
137148

138-
j = str_start[(s) - 65536L];
139-
k = str_start[(t) - 65536L];
140-
while (j < str_start[(s + 1) - 65536L]) {
141-
149+
while (j < str_start[s + 1 - 65536L]) {
142150
if (str_pool[j] != str_pool[k])
143151
return false;
152+
144153
j++;
145154
k++;
146155
}
147156
}
157+
148158
return true;
149159
}
150160

151-
str_number search_string(str_number search)
161+
162+
str_number
163+
search_string(str_number search)
152164
{
153165
str_number s;
154166
int32_t len;
167+
155168
len = length(search);
169+
156170
if (len == 0) {
157171
return EMPTY_STRING;
158172
} else {
159-
160173
s = search - 1;
161-
while (s > 65535L) {
162174

175+
while (s > 65535L) {
163176
if (length(s) == len) {
164-
165177
if (str_eq_str(s, search)) {
166178
return s;
167179
}
168180
}
181+
169182
s--;
170183
}
171184
}
185+
172186
return 0;
173187
}
174188

175-
str_number slow_make_string(void)
189+
190+
str_number
191+
slow_make_string(void)
176192
{
177193
str_number s;
178194
str_number t;
195+
179196
t = make_string();
180197
s = search_string(t);
198+
181199
if (s > 0) {
182-
{
183-
str_ptr--;
184-
pool_ptr = str_start[str_ptr - TOO_BIG_CHAR];
185-
}
200+
str_ptr--;
201+
pool_ptr = str_start[str_ptr - TOO_BIG_CHAR];
186202
return s;
187203
}
204+
188205
return t;
189206
}

0 commit comments

Comments
 (0)