aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2020-04-27 15:46:37 -0700
committerPaul Eggert2020-04-27 15:53:30 -0700
commite49d3a45cd4a0554aa98c45f0976ed513c500951 (patch)
tree3d463db10afc042754f30a5dd301c8839cf4ff8a /src
parent199f146aee3a692a69d80135752d88cae0fe8c49 (diff)
downloademacs-e49d3a45cd4a0554aa98c45f0976ed513c500951.tar.gz
emacs-e49d3a45cd4a0554aa98c45f0976ed513c500951.zip
Improve multibyte_length performance
* src/character.h (multibyte_length): Merge tests so that there are fewer conditional branches. This improved CPU speed of ‘make compile-always’ by about 1.5% on my platform.
Diffstat (limited to 'src')
-rw-r--r--src/character.h42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/character.h b/src/character.h
index d4d77504426..af5023f77cc 100644
--- a/src/character.h
+++ b/src/character.h
@@ -317,30 +317,30 @@ multibyte_length (unsigned char const *p, unsigned char const *pend,
317 return 1; 317 return 1;
318 if (!check || p + 1 < pend) 318 if (!check || p + 1 < pend)
319 { 319 {
320 /* The 'unsigned int' avoids int overflow in the 5-byte case. */ 320 unsigned char d = p[1];
321 unsigned int d = p[1]; 321 int w = ((d & 0xC0) << 2) + c;
322 322 if ((allow_8bit ? 0x2C0 : 0x2C2) <= w && w <= 0x2DF)
323 if (TRAILING_CODE_P (d)) 323 return 2;
324 if (!check || p + 2 < pend)
324 { 325 {
325 if (allow_8bit ? (c & 0xE0) == 0xC0 : 0xC2 <= c && c <= 0xDF) 326 unsigned char e = p[2];
326 return 2; 327 w += (e & 0xC0) << 4;
327 if ((!check || p + 2 < pend) 328 int w1 = w | ((d & 0x20) >> 2);
328 && TRAILING_CODE_P (p[2])) 329 if (0xAE1 <= w1 && w1 <= 0xAEF)
330 return 3;
331 if (!check || p + 3 < pend)
329 { 332 {
330 if ((c & 0xF0) == 0xE0 && ((c & 0x0F) | (d & 0x20))) 333 unsigned char f = p[3];
331 return 3; 334 w += (f & 0xC0) << 6;
332 if ((!check || p + 3 < pend) && TRAILING_CODE_P (p[3])) 335 int w2 = w | ((d & 0x30) >> 3);
336 if (0x2AF1 <= w2 && w2 <= 0x2AF7)
337 return 4;
338 if (!check || p + 4 < pend)
333 { 339 {
334 if ((c & 0xF8) == 0xF0 && ((c & 0x07) | (d & 0x30))) 340 int_fast64_t lw = w + ((p[4] & 0xC0) << 8),
335 return 4; 341 w3 = (lw << 24) + (d << 16) + (e << 8) + f;
336 if (c == 0xF8 && (!check || p + 4 < pend) 342 if (0xAAF8888080 <= w3 && w3 <= 0xAAF88FBFBD)
337 && TRAILING_CODE_P (p[4])) 343 return 5;
338 {
339 unsigned int w = ((d << 24) + (p[2] << 16)
340 + (p[3] << 8) + p[4]);
341 if (0x88808080 <= w && w <= 0x8FBFBDBF)
342 return 5;
343 }
344 } 344 }
345 } 345 }
346 } 346 }