mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
micro-optimize String.eql(String)
This commit is contained in:
@@ -137,20 +137,22 @@ pub const String = packed struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn eql(a: String, b: String) bool {
|
pub fn eql(a: String, b: String) bool {
|
||||||
if (a.len != b.len or a.len < 0 or b.len < 0) {
|
if (@as(*const u64, @ptrCast(&a)).* != @as(*const u64, @ptrCast(&b)).*) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.len <= 12) {
|
const len = a.len;
|
||||||
|
if (len < 0 or b.len < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len <= 12) {
|
||||||
return @reduce(.And, a.payload.content == b.payload.content);
|
return @reduce(.And, a.payload.content == b.payload.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@reduce(.And, a.payload.heap.prefix == b.payload.heap.prefix) == false) {
|
// a.len == b.len at this point
|
||||||
return false;
|
const al: usize = @intCast(len);
|
||||||
}
|
const bl: usize = @intCast(len);
|
||||||
|
|
||||||
const al: usize = @intCast(a.len);
|
|
||||||
const bl: usize = @intCast(a.len);
|
|
||||||
return std.mem.eql(u8, a.payload.heap.ptr[0..al], b.payload.heap.ptr[0..bl]);
|
return std.mem.eql(u8, a.payload.heap.ptr[0..al], b.payload.heap.ptr[0..bl]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user