Skip to content

Optimize Path#drive, #root, and #anchor#15584

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
HertzDevil:perf/path-anchor
Mar 24, 2025
Merged

Optimize Path#drive, #root, and #anchor#15584
straight-shoota merged 1 commit intocrystal-lang:masterfrom
HertzDevil:perf/path-anchor

Conversation

@HertzDevil
Copy link
Contributor

Factors out the body of #drive_and_root to return the end indices of the drive and root parts respectively, instead of constructing substrings immediately.

When both the drive and root are present, which happens to all Windows absolute or UNC paths, this saves a string allocation in #drive / #root, and a string concatenation in #anchor. This also emphasizes by construction the invariant that #drive and #anchor are always prefixes of the whole path if they exist.

@HertzDevil HertzDevil added performance platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:files labels Mar 21, 2025
@straight-shoota straight-shoota added this to the 1.16.0 milestone Mar 21, 2025
@straight-shoota straight-shoota merged commit 5db8f67 into crystal-lang:master Mar 24, 2025
34 of 35 checks passed
@HertzDevil HertzDevil deleted the perf/path-anchor branch March 24, 2025 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants