bytes: make search linear and splits consistent

This commit is contained in:
2026-08-09 17:43:31 +09:00
parent 8620e64313
commit 2d947c469e
4 changed files with 178 additions and 37 deletions

View File

@@ -110,6 +110,27 @@ import bytes;
case let i: i32 => { assert(!(i != 3)); };
case void => abort();
};
// Periodic long needles exercise the two-way path's critical-period
// memory. The first candidate shares a long prefix and must be skipped
// without missing the later match; the second never matches.
let hp: [18]u8;
let np: [7]u8;
let i: i32 = 0;
for (i < 18) { hp[i] = 'a'; i += 1; };
hp[8] = 'b'; hp[17] = 'b';
i = 0;
for (i < 6) { np[i] = 'a'; i += 1; };
np[6] = 'b';
match (bytes.index(hp[0:18], np[0:7])) {
case let off: i32 => { assert(!(off != 2)); };
case void => abort();
};
np[6] = 'c';
match (bytes.index(hp[0:18], np[0:7])) {
case let off: i32 => abort();
case void => void;
};
};
// ref/hare/bytes/index.ha:118.