diff --git a/src/ng/interpolate.js b/src/ng/interpolate.js index b78f44a4c9c5..e0495163b512 100644 --- a/src/ng/interpolate.js +++ b/src/ng/interpolate.js @@ -127,12 +127,11 @@ function $InterpolateProvider() { var startIndex, endIndex, index = 0, - parts = [], length = text.length, hasInterpolation = false, - fn, + fn = null, exp, - concat = []; + parts = []; while(index < length) { if ( ((startIndex = text.indexOf(startSymbol, index)) != -1) && @@ -149,10 +148,9 @@ function $InterpolateProvider() { } } - if (!(length = parts.length)) { + if (!parts.length) { // we added, nothing, must have been an empty string. parts.push(''); - length = 1; } // Concatenating expressions makes it hard to reason about whether some combination of @@ -169,37 +167,101 @@ function $InterpolateProvider() { } if (!mustHaveExpression || hasInterpolation) { - concat.length = length; - fn = function(context) { + var concat = new Array(parts.length), + expressions = {}; + + forEach(parts, function(value, index) { + if (isFunction(value)) { + expressions[index] = value; + } else { + concat[index] = value; + } + }); + + // computes all the interpolations and returns the resulting string + // a specific index might already be computed (thanks to the scope's dirty-checking), + // and so its expression shouldn't be executed a 2nd time + // also populates the lastValues of custom watchers for internal dirty-checking + var getConcatValue = function(scope, computedIndex, computedValue, lastValues) { try { - for(var i = 0, ii = length, part; i