Skip to content

Commit

Permalink
perf: exit loop immediately after finding acTL chunk
Browse files Browse the repository at this point in the history
There is no need to continue searching for `IDAT`,
since it's existence is guaranteed by PNG spec.
  • Loading branch information
madtisa committed Aug 10, 2024
1 parent 16510c7 commit f9dacba
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default function isApng(buffer: Buffer | Uint8Array): boolean {

buffer = buffer.subarray(8)

let foundFirst = false
let firstIndex = 0
let secondIndex = 0
for (let i = 0; i < buffer.length; i++) {
Expand All @@ -48,7 +47,7 @@ export default function isApng(buffer: Buffer | Uint8Array): boolean {
) {
firstIndex++
if (firstIndex === sequences.animationControlChunk.length) {
foundFirst = true
return true
}
}

Expand All @@ -60,7 +59,7 @@ export default function isApng(buffer: Buffer | Uint8Array): boolean {
) {
secondIndex++
if (secondIndex === sequences.imageDataChunk.length) {
return foundFirst
return false
}
}
}
Expand Down

0 comments on commit f9dacba

Please sign in to comment.