diff options
| author | Misko Hevery | 2010-05-30 19:42:21 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2010-05-30 19:42:21 -0700 | 
| commit | 2e33e89a77d115ff17f5841ec328b1c1e4228161 (patch) | |
| tree | 22a97d5c70f2e74ffb4dfe789c82545363abed55 /src/Scope.js | |
| parent | 1aa99c08e9ccd515a333478f00b361f40c622002 (diff) | |
| download | angular.js-2e33e89a77d115ff17f5841ec328b1c1e4228161.tar.bz2 | |
added compiled getterFN for better performance
Diffstat (limited to 'src/Scope.js')
| -rw-r--r-- | src/Scope.js | 35 | 
1 files changed, 35 insertions, 0 deletions
| diff --git a/src/Scope.js b/src/Scope.js index bed0ff6d..1c223130 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -43,6 +43,41 @@ function setter(instance, path, value){    return value;  } +/////////////////////////////////// + +var getterFnCache = {}; +function getterFn(path){ +  var fn = getterFnCache[path]; +  if (fn) return fn; + +  var code = 'function (self){\n'; +  code += '  var last, fn, type;\n'; +  foreach(path.split('.'), function(key) { +    code += '  if(!self) return self;\n'; +    code += '  last = self;\n'; +    code += '  self = self.' + key + ';\n'; +    code += '  if(typeof self == "function") \n'; +    code += '    self = function(){ return last.'+key+'.apply(last, arguments); };\n'; +    if (key.charAt(0) == '$') { +      // special code for super-imposed functions +      var name = key.substr(1); +      code += '  if(!self) {\n'; +      code += '    type = angular.Global.typeOf(last);\n'; +      code += '    fn = (angular[type.charAt(0).toUpperCase() + type.substring(1)]||{})["' + name + '"];\n'; +      code += '    if (fn)\n'; +      code += '      self = function(){ return fn.apply(last, [last].concat(slice.call(arguments, 0, arguments.length))); };\n'; +      code += '  }\n'; +    } +  }); +  code += '  return self;\n}'; +  fn = eval('(' + code + ')'); +  fn.toString = function(){ return code; }; + +  return getterFnCache[path] = fn; +} + +/////////////////////////////////// +  var compileCache = {};  function expressionCompile(exp){    if (isFunction(exp)) return exp; | 
