Skip to content

Commit e837a88

Browse files
committed
Optimize another check out of hot path for UHC decoding
This gives about another 8-9% speed boost to UHC decoding.
1 parent a76658b commit e837a88

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ext/mbstring/libmbfl/filters/mbfilter_uhc.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static size_t mb_uhc_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf,
203203

204204
if (c < 0x80) {
205205
*out++ = c;
206-
} else if (c > 0x80 && c < 0xFE && c != 0xC9) {
206+
} else if (c > 0x80 && c < 0xFE) {
207207
/* We don't need to check p < e here; it's not possible that this pointer dereference
208208
* will be outside the input string, because of e-- above */
209209
unsigned char c2 = *p++;
@@ -221,6 +221,15 @@ static size_t mb_uhc_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf,
221221
w = (c - 0xC7)*94 + c2 - 0xA1;
222222
ZEND_ASSERT(w < uhc3_ucs_table_size);
223223
w = uhc3_ucs_table[w];
224+
if (!w) {
225+
/* If c == 0xC9, we shouldn't have tried to read a 2-byte char at all... but it is faster
226+
* to fix up that rare case here rather than include an extra check in the hot path */
227+
if (c == 0xC9) {
228+
p--;
229+
}
230+
*out++ = MBFL_BAD_INPUT;
231+
continue;
232+
}
224233
}
225234
if (!w) {
226235
w = MBFL_BAD_INPUT;

0 commit comments

Comments
 (0)