Skip to content

Commit 02a0727

Browse files
committed
eqlDocument slicing at hash
1 parent 7c9d725 commit 02a0727

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/browser/URL.zig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,10 @@ pub fn getHost(raw: [:0]const u8) []const u8 {
272272

273273
// Returns true if these two URLs point to the same document.
274274
pub fn eqlDocument(first: [:0]const u8, second: [:0]const u8) bool {
275-
if (!std.mem.eql(u8, getProtocol(first), getProtocol(second))) return false;
276-
if (!std.mem.eql(u8, getHost(first), getHost(second))) return false;
277-
if (!std.mem.eql(u8, getPort(first), getPort(second))) return false;
278-
if (!std.mem.eql(u8, getPathname(first), getPathname(second))) return false;
279-
if (!std.mem.eql(u8, getSearch(first), getSearch(second))) return false;
280-
// hashes are allowed to be different.
281-
282-
return true;
275+
// First '#' signifies the start of the fragment.
276+
const first_hash_index = std.mem.indexOfScalar(u8, first, '#') orelse first.len;
277+
const second_hash_index = std.mem.indexOfScalar(u8, second, '#') orelse second.len;
278+
return std.mem.eql(u8, first[0..first_hash_index], second[0..second_hash_index]);
283279
}
284280

285281
const KnownProtocol = enum {

0 commit comments

Comments
 (0)