-
Notifications
You must be signed in to change notification settings - Fork 623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(bytes): equals()
works with subarray
#4630
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4630 +/- ##
=======================================
Coverage 90.99% 90.99%
=======================================
Files 478 478
Lines 37383 37383
Branches 5308 5308
=======================================
Hits 34016 34016
Misses 3305 3305
Partials 62 62 ☔ View full report in Codecov by Sentry. |
const compressedA = new Uint32Array(a.buffer, 0, compressible); | ||
const compressedB = new Uint32Array(b.buffer, 0, compressible); | ||
const compressedA = new Uint32Array(a, 0, compressible); | ||
const compressedB = new Uint32Array(b, 0, compressible); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
This change fixes the bug but is really bad for performance: import { equals } from "https://raw.githubusercontent.com/denoland/deno_std/0052a36/bytes/equals.ts"
const a999 = new Uint8Array(999);
const b999 = new Uint8Array(999);
const a1k = new Uint8Array(1000);
const b1k = new Uint8Array(1000);
Deno.bench("999", () => {
equals(a999, b999)
})
Deno.bench("1k", () => {
equals(a1k, b1k)
})
The "optimized" As @0f-0b pointed out, the I don't think this function should be allocating memory at all (for one thing, it makes the function always O(N), even if the first byte differs). Instead, the |
See #4632 |
Fixes #3603