-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
url: optimize path resolution with single-pass algorithm #61395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Review requested:
|
ad0cf95 to
670d025
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61395 +/- ##
========================================
Coverage 88.51% 88.52%
========================================
Files 704 704
Lines 208814 208927 +113
Branches 40316 40343 +27
========================================
+ Hits 184840 184954 +114
- Misses 15964 15965 +1
+ Partials 8010 8008 -2
🚀 New features to boost your workflow:
|
| * @returns {{ segments: string[], up: number, trailingSlash: boolean }} | ||
| */ | ||
| function normalizePathSegments(path, allowAboveRoot) { | ||
| if (!path) return { segments: [], up: 0, trailingSlash: false }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (!path) return { segments: [], up: 0, trailingSlash: false }; | |
| if (!path) { | |
| return { | |
| __proto__: null, | |
| segments: [], | |
| up: 0, | |
| trailingSlash: false, | |
| } | |
| } |
| } else if (segment === '..') { | ||
| // Parent directory | ||
| if (segments.length > 0 && segments[segments.length - 1] !== '..') { | ||
| segments.pop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| segments.pop(); | |
| ArrayPrototypePop(segments); |
| // If path ends with /, ., or .., we need a trailing slash | ||
| trailingSlash = lastSeg === '' || lastSeg === '.' || lastSeg === '..'; | ||
|
|
||
| return { segments, up, trailingSlash }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return { segments, up, trailingSlash }; | |
| return { | |
| __proto__: null, | |
| segments, | |
| up, | |
| trailingSlash, | |
| } |
| // Handle mustEndAbs - ensure path starts with / | ||
| let isAbsolute = srcPath.length > 0 && srcPath[0] === ''; | ||
| if (!isAbsolute && srcPath.length > 0 && srcPath[0] && | ||
| srcPath[0].charAt(0) === '/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| srcPath[0].charAt(0) === '/') { | |
| srcPath[0][0] === '/') { |
| if (result.host) { | ||
| // Remove the host from srcPath (first element) | ||
| srcPath = srcPath.length > 1 ? | ||
| ArrayPrototypeJoin(srcPath, '/').slice(result.host.length + 1).split('/') : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Primordials
Includes multiple optimizations to avoid opening multiple pull-requests.
My local benchmarks show 2x-3x improvement. Let's see what the CI says.
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1782/console