joyent/node — pull request #8724 by woollybogger (2014-11-14 01:13:27+00:00)
Title: path: refactor normalizeArray() - improve performance

Improves performance of `path.normalize()` and `path.resolve()` (up to 3x faster in some cases).

#8342 didn't look like anyone was paying attention to it anymore so I came up with a solution that addresses @trevnorris's issue with it.

I used @dead-horse's same [test code](https://gist.github.com/dead-horse/ae3d6d34b6ec44d8d6ed) to obtain the following benchmarks:

Test | Original | dead-horse | This PR
---------------------------|----------|------------|---------
normalize simple path | 353 ms | 351 ms | 335 ms
resolve simple path | 1709 ms | 920 ms | 910 ms
normalize path contains . | 885 ms | 388 ms | 357 ms
resolve path contains . | 2653 ms | 1000 ms | 975 ms
normalize path contains .. | 1186 ms | 553 ms | 370 ms
resolve path contains .. | 2973 ms | 1223 ms | 1017 ms

Addressing @trevnorris's issue with using `Array#reverse()` didn't affect the first 4 tests much but removing it seems to have improved performance on the last 2 tests.