Skip to content

Commit

Permalink
refactor: uses traditional for loop for small copy
Browse files Browse the repository at this point in the history
  • Loading branch information
rinsuki committed Jun 21, 2021
1 parent f612a5b commit 8589ea9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/index.ts
Expand Up @@ -63,7 +63,14 @@ function copy(
si: number,
len: number
): void {
dest.set(src.subarray(si, si + len), di);
// traditional for loop is faster than Uint8Array#set if length is small (<20?)
if (len < 20) {
for (let i = 0; i<len; i++) {
dest[di + i] = src[si + i]
}
} else {
dest.set(src.subarray(si, si + len), di);
}
}

export function calcUncompressedLen(src: Uint8Array): number {
Expand Down

0 comments on commit 8589ea9

Please sign in to comment.