mem: Short-circuit identical slices
64c08de4141027e69f06d051badd9b3973553bc9e5e046bc5ac5d50c7090e816
`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
1 parent
69f92d23
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 | } |