Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,20 +1236,20 @@ const posix = {
join(...args) {
if (args.length === 0)
return '.';
let joined;

const path = [];
for (let i = 0; i < args.length; ++i) {
const arg = args[i];
validateString(arg, 'path');
if (arg.length > 0) {
if (joined === undefined)
joined = arg;
else
joined += `/${arg}`;
path.push(arg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a primordial?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I use ArrayPrototypePush, the benchmark result is as follows.

                                                               confidence improvement accuracy (*)   (**)  (***)
path/join-posix.js n=100000 paths='/foo|bar||baz/asdf|quux|..'                 0.20 %       ±0.63% ±0.84% ±1.09%

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the primordial is needed here, regardless of benchmark results.

CC @nodejs/primordials

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using primordials are not required. If we see a critical performance impact, just like this, we should avoid using it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are they not required? This isn't the error path.

What about an alternative:

Suggested change
path.push(arg);
path[path.length - 1] = arg;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primordials are used elsewhere in this function, shouldn't they be used here, or removed from the other spots?

}
}
if (joined === undefined)

if (path.length === 0)
return '.';
return posix.normalize(joined);

return posix.normalize(ArrayPrototypeJoin(path, '/'));
},

/**
Expand Down