Skip to content

Commit

Permalink
refactor: reuse sizeOfLength
Browse files Browse the repository at this point in the history
  • Loading branch information
seia-soto committed Dec 12, 2024
1 parent 3270e6a commit 47dc63a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/adblocker/src/data-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ export class StaticDataView {
public pushUTF8(raw: string): void {
const pos = this.getPos();
// Assume the size of output length is 1 (which means output is less than 128)
// based on the possible minimal length to avoid memory reallocation.
// based on the possible minimal length to avoid memory relocation.
// The minimal length is always 1 byte per character.
const start = pos + (raw.length > 127 ? 5 : 1);
const start = pos + sizeOfLength(raw.length);
const { written } = TEXT_ENCODER.encodeInto(raw, this.buffer.subarray(start));
// If we failed to predict, that means the required bytes for length is 5.
if (pos + sizeOfLength(written) !== start) {
Expand Down

0 comments on commit 47dc63a

Please sign in to comment.