Optimize UTF-8 handling in getUtf8CharSize() by using logic instead of table lookup (memory fetch) for bytes<128

This commit is contained in:
Ivan Skytte Jørgensen
2015-09-07 13:32:36 +02:00
parent 21766acdfd
commit 620a367c3c

@ -66,15 +66,26 @@ static int utf8_sane[] = {
// how many bytes is char pointed to by p?
inline char getUtf8CharSize ( uint8_t *p ) {
return bytes_in_utf8_code[*p];
uint8_t c = *p;
if(c<128)
return 1;
else
return bytes_in_utf8_code[c];
}
inline char getUtf8CharSize ( char *p ) {
return bytes_in_utf8_code[*(uint8_t *)p];
uint8_t c = (uint8_t)*p;
if(c<128)
return 1;
else
return bytes_in_utf8_code[c];
}
inline char getUtf8CharSize ( uint8_t c ) {
return bytes_in_utf8_code[c];
if(c<128)
return 1;
else
return bytes_in_utf8_code[c];
}
inline char getUtf8CharSize2 ( uint8_t *p ) {