mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: optimise sx == sy
in the case where strings have common prefixes
This commit is contained in:
parent
e9fa53b0c1
commit
7f12bfa563
@ -496,6 +496,7 @@ pub fn (s string) u64() u64 {
|
||||
}
|
||||
|
||||
// eq implements the `s == a` (equal) operator.
|
||||
[direct_array_access]
|
||||
fn (s string) eq(a string) bool {
|
||||
if s.str == 0 {
|
||||
// should never happen
|
||||
@ -504,6 +505,12 @@ fn (s string) eq(a string) bool {
|
||||
if s.len != a.len {
|
||||
return false
|
||||
}
|
||||
if s.len > 0 {
|
||||
last_idx := s.len - 1
|
||||
if s[last_idx] != a[last_idx] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
return C.memcmp(s.str, a.str, a.len) == 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user