fs: improve mkdtemp performance for buffer prefix · nodejs/node@7421467 · GitHub
Skip to content

Commit 7421467

Browse files
anonrigRafaelGSS
authored andcommitted
fs: improve mkdtemp performance for buffer prefix
PR-URL: #51078 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 5453abd commit 7421467

3 files changed

Lines changed: 50 additions & 17 deletions

File tree

benchmark/fs/bench-mkdtempSync.js

Lines changed: 43 additions & 0 deletions

lib/fs.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,16 +2933,9 @@ function mkdtemp(prefix, options, callback) {
29332933
prefix = getValidatedPath(prefix, 'prefix');
29342934
warnOnNonPortableTemplate(prefix);
29352935

2936-
let path;
2937-
if (typeof prefix === 'string') {
2938-
path = `${prefix}XXXXXX`;
2939-
} else {
2940-
path = Buffer.concat([prefix, Buffer.from('XXXXXX')]);
2941-
}
2942-
29432936
const req = new FSReqCallback();
29442937
req.oncomplete = callback;
2945-
binding.mkdtemp(path, options.encoding, req);
2938+
binding.mkdtemp(prefix, options.encoding, req);
29462939
}
29472940

29482941
/**
@@ -2956,15 +2949,7 @@ function mkdtempSync(prefix, options) {
29562949

29572950
prefix = getValidatedPath(prefix, 'prefix');
29582951
warnOnNonPortableTemplate(prefix);
2959-
2960-
let path;
2961-
if (typeof prefix === 'string') {
2962-
path = `${prefix}XXXXXX`;
2963-
} else {
2964-
path = Buffer.concat([prefix, Buffer.from('XXXXXX')]);
2965-
}
2966-
2967-
return binding.mkdtemp(path, options.encoding);
2952+
return binding.mkdtemp(prefix, options.encoding);
29682953
}
29692954

29702955
/**

src/node_file.cc

Lines changed: 5 additions & 0 deletions

0 commit comments

Comments
 (0)