querystring: improve escape() performance

This commit improves escape() performance by up to 15% with the
existing querystring-stringify benchmarks by reducing the number
of string concatentations. A potential deopt is also avoided by
making sure the index passed to charCodeAt() is within bounds.

PR-URL: https://github.com/nodejs/node/pull/5012
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Brian White authored and Rod Vagg committed 2016-02-15 23:14:13 +11:00
1 parent 27e323e8c1
commit 46be1f4d0c
2 files changed
+24 -11

No files matched your search

@@ -4,7 +4,7 @@ var v8 = require('v8');
var bench = common.createBenchmark(main, {
type: ['noencode', 'encodemany', 'encodelast'],
n: [1e6],
n: [1e7],
});
function main(conf) {
@@ -37,6 +37,7 @@ function main(conf) {
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(querystring.stringify)');
querystring.stringify(input);
bench.start();
for (var i = 0; i < n; i += 1)