Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use string concatenation to build the output string #470

Merged
merged 1 commit into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion benchmark/bench-ejs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

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 runs = 9; // min 4 for median
Expand Down
6 changes: 4 additions & 2 deletions lib/ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ Template.prototype = {

if (!this.source) {
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) {
prepended += ' var ' + opts.outputFunctionName + ' = __append;' + '\n';
}
Expand All @@ -591,7 +593,7 @@ Template.prototype = {
prepended += ' with (' + opts.localsName + ' || {}) {' + '\n';
appended += ' }' + '\n';
}
appended += ' return __output.join("");' + '\n';
appended += ' return __output;' + '\n';
this.source = prepended + this.source + appended;
}

Expand Down