path: refactor for performance and consistency#1778
path: refactor for performance and consistency#1778nwoltman wants to merge 2 commits intonodejs:masterfrom nwoltman:path
Conversation
lib/path.js
Outdated
There was a problem hiding this comment.
First letter should be capitalized.
|
Are there any API changes? (seeing that the tests were modified) |
|
@silverwind I'm not sure if this counts as an API change, but as discussed here, if a user passes in an object where the |
|
I'm keen on getting the benchmark in ( |
|
@jbergstroem It looks like each |
|
Looks like #1752 conflicts with this. I will remove the Btw,
Is also valid for this PR. |
|
LGTM |
|
Why using |
|
@jbergstroem I added some benchmarks. Do those look about right? |
|
@woollybogger apologies for the late reply. LGTM. CI here: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/827/ |
|
@jbergstroem A couple unrelated (and possibly flaky) tests failed. Does that matter? |
|
@woollybogger no, that's something we're working on improving. I can't access the old results -- can you rebase on top of latest master so we can get a new run going? You might want to see if anyone else wants to review before I/someone else look at landing it. @ChALkeR? |
|
Rebased |
|
(never mind the windows timeouts) |
|
The main part ( Minor thing: you replace single-char posix.isAbsolute = function(path) {
assertPath(path);
return path.charAt(0) === '/';
};Could you fix that for consistency? |
|
@ChALkeR Fixed. |
There was a problem hiding this comment.
I am not sure if returning the original array and a new array based on conditions is a good idea.
There was a problem hiding this comment.
It's just a little helper function. There's no point in making a copy of an array when the original is all you need.
|
bump 🚅 |
lib/path.js
Outdated
There was a problem hiding this comment.
Could use shorthand properties here:
return {
device,
isUnc,
isAbsolute: isUnc || !!result[2], // UNC paths are always absolute
tail: result[3]
};|
LGTM, few nits and a question above. |
Improve performance by: + Not leaking the `arguments` object! + Getting the last character of a string by index, instead of with `.substr()` or `.slice()` Improve code consistency by: + Using `[]` instead of `.charAt()` where possible + Using a function declaration instead of a var declaration + Using `.slice()` with clearer arguments + Checking if `dir` is truthy in `win32.format` (added tests for this) Improve both by: + Making the reusable `trimArray()` function + Standardizing getting certain path statistics with the new `win32StatPath()` function
Path functions being benchmarked are: * format * isAbsolute * join * normalize * relative * resolve
|
Updated |
|
LGTM |
Improve performance by: + Not leaking the `arguments` object! + Getting the last character of a string by index, instead of with `.substr()` or `.slice()` Improve code consistency by: + Using `[]` instead of `.charAt()` where possible + Using a function declaration instead of a var declaration + Using `.slice()` with clearer arguments + Checking if `dir` is truthy in `win32.format` (added tests for this) Improve both by: + Making the reusable `trimArray()` function + Standardizing getting certain path statistics with the new `win32StatPath()` function PR-URL: #1778 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Path functions being benchmarked are: * format * isAbsolute * join * normalize * relative * resolve PR-URL: #1778 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Improve performance by: + Not leaking the `arguments` object! + Getting the last character of a string by index, instead of with `.substr()` or `.slice()` Improve code consistency by: + Using `[]` instead of `.charAt()` where possible + Using a function declaration instead of a var declaration + Using `.slice()` with clearer arguments + Checking if `dir` is truthy in `win32.format` (added tests for this) Improve both by: + Making the reusable `trimArray()` function + Standardizing getting certain path statistics with the new `win32StatPath()` function PR-URL: nodejs#1778 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Path functions being benchmarked are: * format * isAbsolute * join * normalize * relative * resolve PR-URL: nodejs#1778 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Convergence PR prompted by #35
Original PR: nodejs/node-v0.x-archive#9289
Original PR message (slightly modified):
Improve performance by:
argumentsobject inwin32.join.substr()or.slice()Improve code consistency by:
[]instead of.charAt()where possible.slice()with clearer argumentsImprove both by:
trimArray()functionwin32StatPath()functionBenchmarks: (higher is better)
Benchmark code (gist)