mem: Short-circuit identical slices

abd19748a096878108a455f9c0b6d8afa244b2f533849ab65289ae64e1471e13
`eq` compared every byte even when equal-length slices shared the
same backing address.

Recognize pointer identity after checking the lengths. Canonical
strings and repeated slice comparisons can now return without
traversing their contents.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent f2ff6b8e
lib/std/mem.rad +3 -0
56 56
/// Check whether two byte slices have the same length and contents.
57 57
export fn eq(a: *[u8], b: *[u8]) -> bool {
58 58
    if a.len <> b.len {
59 59
        return false;
60 60
    }
61 +
    if a.ptr == b.ptr {
62 +
        return true;
63 +
    }
61 64
    for i in 0..a.len {
62 65
        if a[i] <> b[i] {
63 66
            return false;
64 67
        }
65 68
    }