mirror of
https://github.com/CryptKeeperZK/ejs.git
synced 2026-01-09 15:37:57 -05:00
Use string concatenation to build the output string
Switching from pushing to an array and using .join() to using simple string concatenation yields performance gains up to 260%.
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ejs = require('..');
|
var ejs = require('..');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
ejs.fileLoader = function(n) { return files[n.replace(/^\//, '').replace(/\.ejs$/, '')]; };
|
ejs.fileLoader = function(n) { return files[path.basename(n, '.ejs')]; };
|
||||||
|
|
||||||
var loops = 10000;
|
var loops = 10000;
|
||||||
var runs = 9; // min 4 for median
|
var runs = 9; // min 4 for median
|
||||||
|
|||||||
@@ -572,7 +572,9 @@ Template.prototype = {
|
|||||||
|
|
||||||
if (!this.source) {
|
if (!this.source) {
|
||||||
this.generateSource();
|
this.generateSource();
|
||||||
prepended += ' var __output = [], __append = __output.push.bind(__output);' + '\n';
|
prepended +=
|
||||||
|
' var __output = "";\n' +
|
||||||
|
' function __append(s) { if (s !== undefined && s !== null) __output += s }\n';
|
||||||
if (opts.outputFunctionName) {
|
if (opts.outputFunctionName) {
|
||||||
prepended += ' var ' + opts.outputFunctionName + ' = __append;' + '\n';
|
prepended += ' var ' + opts.outputFunctionName + ' = __append;' + '\n';
|
||||||
}
|
}
|
||||||
@@ -591,7 +593,7 @@ Template.prototype = {
|
|||||||
prepended += ' with (' + opts.localsName + ' || {}) {' + '\n';
|
prepended += ' with (' + opts.localsName + ' || {}) {' + '\n';
|
||||||
appended += ' }' + '\n';
|
appended += ' }' + '\n';
|
||||||
}
|
}
|
||||||
appended += ' return __output.join("");' + '\n';
|
appended += ' return __output;' + '\n';
|
||||||
this.source = prepended + this.source + appended;
|
this.source = prepended + this.source + appended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user