builtin: optimise `sx == sy` in the case where strings have common prefixes
parent
e9fa53b0c1
commit
7f12bfa563
|
@ -496,6 +496,7 @@ pub fn (s string) u64() u64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// eq implements the `s == a` (equal) operator.
|
// eq implements the `s == a` (equal) operator.
|
||||||
|
[direct_array_access]
|
||||||
fn (s string) eq(a string) bool {
|
fn (s string) eq(a string) bool {
|
||||||
if s.str == 0 {
|
if s.str == 0 {
|
||||||
// should never happen
|
// should never happen
|
||||||
|
@ -504,6 +505,12 @@ fn (s string) eq(a string) bool {
|
||||||
if s.len != a.len {
|
if s.len != a.len {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if s.len > 0 {
|
||||||
|
last_idx := s.len - 1
|
||||||
|
if s[last_idx] != a[last_idx] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
return C.memcmp(s.str, a.str, a.len) == 0
|
return C.memcmp(s.str, a.str, a.len) == 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue