Skip to content

path: refactor for performance and consistency

Rodrigo Muino Tomonari requested to merge github/fork/nwoltman/path into master

Convergence PR prompted by nodejs/node#35 Original PR: joyent/node#9289

Original PR message (slightly modified):


Improve performance by:

  • Not leaking the arguments object in win32.join
  • 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

Improve both by:

  • Making the reusable trimArray() function
  • Standardizing getting certain path statistics with the new win32StatPath() function

Benchmarks: (higher is better)

function (path.) current (ops/sec) this PR (ops/sec)
win32.resolve 315,019 399,543
win32.normalize 873,559 1,051,170
win32.isAbsolute 1,915,332 1,939,849
win32.join 452,879 815,033
win32.relative 153,821 219,928
win32.format 13,118,588 16,364,384
posix.relative 244,638 304,456
Benchmark code (gist)

Merge request reports

Loading