Browse Source

Optimize for ASCII characters in ord()

This yields a 60% performance improvement on a typical HTML document
labels
J. King 6 years ago
parent
commit
aa58f619d7
  1. 9
      lib/UTF8.php

9
lib/UTF8.php

@ -185,10 +185,17 @@ abstract class UTF8 {
// character rather than a whole stream
$eof = strlen($string);
start:
// optimization for ASCII characters
if ($pos < $eof) {
$b = $string[$pos];
if ($b < "\x80") {
$next = $pos + 1;
return ord($b);
}
}
$point = null;
$seen = 0;
$needed = 0;
$next = $pos + 1;
$lower = "\x80";
$upper = "\xBF";
while ($pos < $eof && !($needed && $seen >= $needed)) {

Loading…
Cancel
Save