calculation in bytes simply because we always know the byte
length. squareroot has the same ordering as the positive value,
so don't bother with the actual square root. */
- const float existing = THREEWAY_SQUARE(0, cache[3], cache[1], blen);
if (byte > cache[1]) {
/* New position is after the existing pair of pairs. */
const float keep_earlier
= THREEWAY_SQUARE(0, cache[1], byte, blen);
if (keep_later < keep_earlier) {
- if (keep_later < existing) {
- cache[2] = cache[0];
- cache[3] = cache[1];
- cache[0] = utf8;
- cache[1] = byte;
- }
+ cache[2] = cache[0];
+ cache[3] = cache[1];
+ cache[0] = utf8;
+ cache[1] = byte;
}
else {
- if (keep_earlier < existing) {
- cache[0] = utf8;
- cache[1] = byte;
- }
+ cache[0] = utf8;
+ cache[1] = byte;
}
}
else if (byte > cache[3]) {
= THREEWAY_SQUARE(0, byte, cache[1], blen);
if (keep_later < keep_earlier) {
- if (keep_later < existing) {
- cache[2] = utf8;
- cache[3] = byte;
- }
+ cache[2] = utf8;
+ cache[3] = byte;
}
else {
- if (keep_earlier < existing) {
- cache[0] = utf8;
- cache[1] = byte;
- }
+ cache[0] = utf8;
+ cache[1] = byte;
}
}
else {
= THREEWAY_SQUARE(0, byte, cache[1], blen);
if (keep_later < keep_earlier) {
- if (keep_later < existing) {
- cache[2] = utf8;
- cache[3] = byte;
- }
+ cache[2] = utf8;
+ cache[3] = byte;
}
else {
- if (keep_earlier < existing) {
- cache[0] = cache[2];
- cache[1] = cache[3];
- cache[2] = utf8;
- cache[3] = byte;
- }
+ cache[0] = cache[2];
+ cache[1] = cache[3];
+ cache[2] = utf8;
+ cache[3] = byte;
}
}
}
use strict;
-plan(tests => 1);
+plan(tests => 2);
my $pid = open CHILD, '-|';
die "kablam: $!\n" unless defined $pid;
\s+ MG_LEN \s = .* \n }xm;
unlike($_, qr{ $utf8magic $utf8magic }x);
+
+# With bad caching, this code used to go quadratic and take 10s of minutes.
+# The 'test' in this case is simply that it doesn't hang.
+
+{
+ local ${^UTF8CACHE} = 1; # enable cache, disable debugging
+ my $x = "\x{100}" x 1000000;
+ while ($x =~ /./g) {
+ my $p = pos($x);
+ }
+ pass("quadratic pos");
+}