Skip to content

Commit b288cb0

Browse files
committed
minor performance improvements
1 parent b2b1700 commit b288cb0

4 files changed

Lines changed: 23 additions & 16 deletions

File tree

src/Angular.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var consoleNode,
1616
msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)),
1717
jqLite = jQuery || jqLiteWrap,
1818
slice = Array.prototype.slice,
19-
error = window['console'] ? bind(window['console'], window['console']['error']) : noop,
19+
error = window['console'] ? bind(window['console'], window['console']['error'] || noop) : noop,
2020
angular = window['angular'] || (window['angular'] = {}),
2121
angularTextMarkup = extensionMap(angular, 'textMarkup'),
2222
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
@@ -292,12 +292,14 @@ function escapeAttr(html) {
292292
}
293293

294294
function bind(_this, _function) {
295-
if (!isFunction(_function))
296-
throw "Not a function!";
297295
var curryArgs = slice.call(arguments, 2, arguments.length);
298-
return function() {
299-
return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
300-
};
296+
return curryArgs.length == 0 ?
297+
function() {
298+
return _function.apply(_this, arguments);
299+
} :
300+
function() {
301+
return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
302+
};
301303
}
302304

303305
function outerHTML(node) {
@@ -331,12 +333,12 @@ function merge(src, dst) {
331333
}
332334
}
333335

334-
function compile(element, parentScope, overrides) {
336+
function compile(element, parentScope) {
335337
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget),
336338
$element = jqLite(element),
337339
parent = extend({}, parentScope);
338340
parent.$element = $element;
339-
return compiler.compile($element)($element, parent, overrides);
341+
return compiler.compile($element)($element, parent);
340342
}
341343
/////////////////////////////////////////////////
342344

src/Compiler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Template.prototype = {
3030
element = jqLite(element);
3131
foreach(this.inits, function(fn) {
3232
queue.push(function(scope) {
33-
scope.$tryEval(fn, element, element);
33+
scope.$tryEval(function(){
34+
return fn.call(scope, element);
35+
}, element);
3436
});
3537
});
3638

src/Scope.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function createScope(parent, services, existing) {
131131

132132
$eval: function $eval(exp) {
133133
if (exp !== undefined) {
134-
return expressionCompile(exp).apply(instance, slice.call(arguments, 1, arguments.length));
134+
return expressionCompile(exp).call(instance);
135135
} else {
136136
for ( var i = 0, iSize = evalLists.sorted.length; i < iSize; i++) {
137137
for ( var queue = evalLists.sorted[i],
@@ -145,7 +145,7 @@ function createScope(parent, services, existing) {
145145

146146
$tryEval: function (expression, exceptionHandler) {
147147
try {
148-
return expressionCompile(expression).apply(instance, slice.call(arguments, 2, arguments.length));
148+
return expressionCompile(expression).call(instance);
149149
} catch (e) {
150150
(instance.$log || {error:error}).error(e);
151151
if (isFunction(exceptionHandler)) {
@@ -161,12 +161,15 @@ function createScope(parent, services, existing) {
161161
$watch: function(watchExp, listener, exceptionHandler) {
162162
var watch = expressionCompile(watchExp),
163163
last;
164+
listener = expressionCompile(listener);
164165
function watcher(){
165166
var value = watch.call(instance),
166167
lastValue = last;
167168
if (last !== value) {
168169
last = value;
169-
instance.$tryEval(listener, exceptionHandler, value, lastValue);
170+
instance.$tryEval(function(){
171+
return listener.call(instance, value, lastValue);
172+
}, exceptionHandler);
170173
}
171174
}
172175
instance.$onEval(PRIORITY_WATCH, watcher);

test/ScopeSpec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ describe('scope/model', function(){
2121
});
2222

2323
describe('$eval', function(){
24-
it('should eval function with correct this and pass arguments', function(){
24+
it('should eval function with correct this', function(){
2525
var model = createScope();
26-
model.$eval(function(name){
27-
this.name = name;
28-
}, 'works');
26+
model.$eval(function(){
27+
this.name = 'works';
28+
});
2929
expect(model.name).toEqual('works');
3030
});
3131

0 commit comments

Comments
 (0)