1
0
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:
Delyan Angelov 2021-05-23 17:22:57 +03:00
parent e9fa53b0c1
commit 7f12bfa563
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -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
}