Skip to content

Optimize getEntry performance in ZipInputStreamZipEntrySource using O(1) case-insensitive lookups#1144

Merged
pjfanning merged 1 commit into
apache:trunkfrom
kali834x:fix-zip-input-stream-entry-source-turkish-locale
Jun 15, 2026
Merged

Optimize getEntry performance in ZipInputStreamZipEntrySource using O(1) case-insensitive lookups#1144
pjfanning merged 1 commit into
apache:trunkfrom
kali834x:fix-zip-input-stream-entry-source-turkish-locale

Conversation

@kali834x

Copy link
Copy Markdown
Contributor

Entry names are normalized and lowercased before being stored in the zipEntries map:

name = IOUtils.normalizePath(name).toLowerCase(Locale.ROOT);

However, getEntry() performs its initial lookup using a non-lowercased key:

final ZipArchiveEntry ze = zipEntries.get(normalizedPath);

As a result, lookups for mixed-case paths may miss the direct map lookup and fall back to a linear case-insensitive scan of all entries, degrading lookup performance from O(1) to O(N).

Solution

Apply the same normalization strategy during lookup:

return zipEntries.get(normalizedPath.toLowerCase(Locale.ROOT));

This makes lookup behavior consistent with key storage, restores O(1) retrieval, and removes the need for the fallback linear scan.

…rce and eliminates an unnecessary O(N) fallback scan
@kali834x kali834x force-pushed the fix-zip-input-stream-entry-source-turkish-locale branch from 877b040 to 3921bce Compare June 15, 2026 04:59

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@pjfanning pjfanning merged commit d0d23e1 into apache:trunk Jun 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants