Skip to content

refactor: use and simplify is_dir#776

Merged
Pr0methean merged 5 commits into
masterfrom
refactor-is-dir
Apr 15, 2026
Merged

refactor: use and simplify is_dir#776
Pr0methean merged 5 commits into
masterfrom
refactor-is-dir

Conversation

@Its-Just-Nans

@Its-Just-Nans Its-Just-Nans commented Apr 11, 2026

Copy link
Copy Markdown
Member

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This refactoring successfully consolidates the is_dir logic into a single, reusable function in src/spec.rs and simplifies the implementation. The change from manual character iteration to ends_with(['/', '\\']) is cleaner and more idiomatic. All usages have been properly updated to use the centralized function.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the is_dir logic by centralizing it into a utility function and simplifying the implementation using ends_with. It also cleans up the codebase by removing an unused dead_code attribute. The review feedback suggests a performance optimization for the is_dir function in src/spec.rs, recommending a byte-level check to avoid unnecessary UTF-8 decoding.

Comment thread src/spec.rs Outdated
.chars()
.next_back()
.is_some_and(|c| c == '/' || c == '\\')
filename.ends_with(['/', '\\'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While ends_with is idiomatic, for a high-performance crate like zip, we can avoid UTF-8 decoding of the last character by performing a byte-level check. Since / and \ are ASCII, they are represented as single bytes in UTF-8 and cannot appear as part of a multi-byte sequence. This optimization is safe and more efficient for a core utility function.

Suggested change
filename.ends_with(['/', '\\'])
matches!(filename.as_bytes().last(), Some(b'/') | Some(b'\\'))

Its-Just-Nans and others added 4 commits April 11, 2026 16:37
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: n4n5 <git@n4n5.dev>
@Its-Just-Nans Its-Just-Nans self-assigned this Apr 12, 2026
@Pr0methean Pr0methean added this pull request to the merge queue Apr 15, 2026
Merged via the queue into master with commit 245b694 Apr 15, 2026
133 checks passed
@Pr0methean Pr0methean deleted the refactor-is-dir branch April 15, 2026 21:40
@Pr0methean Pr0methean mentioned this pull request Apr 15, 2026
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