Optimize _.template when no evaluate delimiters are used and optimize _.bind when partially applied in V8.

Former-commit-id: 25489d41ba3cac7ac3f1414e09f1971a11a779be
This commit is contained in:
John-David Dalton
2012-07-02 00:07:22 -04:00
parent 6af4652161
commit 3b4074bfc7
3 changed files with 113 additions and 73 deletions

View File

@@ -301,7 +301,7 @@
* @returns {String} Returns the formatted source.
*/
function getFunctionSource(func) {
var source = (func + '');
var source = func.source || (func + '');
return source.replace(/\n(?:.*)/g, function(match, index) {
match = match.slice(1);
return (
@@ -465,19 +465,6 @@
return removeFromCreateIterator(source, varName);
}
/**
* Removes non-syntax critical whitespace from a string.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the source with whitespace removed.
*/
function removeWhitespace(source) {
return source.replace(/\[object |else if|function | in |return\s+[\w']|throw |typeof |var |@ |\\\\n|\\n|\s+/g, function(match) {
return match == false || match == '\\n' ? '' : match;
});
}
/*--------------------------------------------------------------------------*/
// Backbone build
@@ -720,8 +707,8 @@
}
else {
// inline `iteratorTemplate` template
source = source.replace(/(( +)var iteratorTemplate *= *)([\s\S]+?\n\2.+?);\n/, (function() {
var code = getFunctionSource(lodash._iteratorTemplate.source);
source = source.replace(/(( +)var iteratorTemplate *= *)[\s\S]+?\n\2.+?;\n/, (function() {
var code = getFunctionSource(lodash._iteratorTemplate);
// expand properties to avoid having to use a with-statement
iteratorOptions.forEach(function(property) {
@@ -735,7 +722,6 @@
.replace(/__p *\+= *' *';/g, '')
.replace(/(__p *\+= *)' *' *\+/g, '$1')
.replace(/\+\s*' *';/g, ';')
.replace(/';(?:\\n|\s)*} *'/g, "'}'")
.replace(/(\{) *;|; *(\})/g, '$1$2')
.replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '$1');