Skip to content

Commit ef114f9

Browse files
committed
Simplify code for conversion of UHC to Unicode
I was hoping to get some performance gains here, but the performance is just the same as before, +/- a fraction of a percent.
1 parent 0f4d37d commit ef114f9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

ext/mbstring/libmbfl/filters/mbfilter_uhc.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,24 @@ static size_t mb_uhc_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf,
208208
*out++ = c;
209209
} else if (c > 0x80 && c < 0xFE && c != 0xC9 && p < e) {
210210
unsigned char c2 = *p++;
211+
if (c2 < 0x41 || c2 == 0xFF) {
212+
*out++ = MBFL_BAD_INPUT;
213+
continue;
214+
}
211215
unsigned int w = 0;
212216

213-
if (c >= 0x81 && c <= 0xA0 && c2 >= 0x41 && c2 <= 0xFE) {
214-
w = (c - 0x81)*190 + (c2 - 0x41);
217+
if (c <= 0xA0) {
218+
w = (c - 0x81)*190 + c2 - 0x41;
215219
if (w < uhc1_ucs_table_size) {
216220
w = uhc1_ucs_table[w];
217221
}
218-
} else if (c >= 0xA1 && c <= 0xC6 && c2 >= 0x41 && c2 <= 0xFE) {
219-
w = (c - 0xA1)*190 + (c2 - 0x41);
222+
} else if (c <= 0xC6) {
223+
w = (c - 0xA1)*190 + c2 - 0x41;
220224
if (w < uhc2_ucs_table_size) {
221225
w = uhc2_ucs_table[w];
222226
}
223-
} else if (c >= 0xC7 && c < 0xFE && c2 >= 0xA1 && c2 <= 0xFE) {
224-
w = (c - 0xC7)*94 + (c2 - 0xA1);
227+
} else if (c2 >= 0xA1) {
228+
w = (c - 0xC7)*94 + c2 - 0xA1;
225229
if (w < uhc3_ucs_table_size) {
226230
w = uhc3_ucs_table[w];
227231
}

0 commit comments

Comments
 (0)