mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-12 22:35:30 +08:00
perf(scope): 10x. Share the child scope class.
This change causes Scope.$destory to run 10x faster. I suspect Scope.$new is significantly faster as well, but I didn't measure it.
This commit is contained in:
@@ -181,18 +181,23 @@ function $RootScopeProvider(){
|
||||
child.$$asyncQueue = this.$$asyncQueue;
|
||||
child.$$postDigestQueue = this.$$postDigestQueue;
|
||||
} else {
|
||||
ChildScope = function() {}; // should be anonymous; This is so that when the minifier munges
|
||||
// the name it does not become random set of chars. This will then show up as class
|
||||
// name in the web inspector.
|
||||
ChildScope.prototype = this;
|
||||
child = new ChildScope();
|
||||
child.$id = nextUid();
|
||||
// Only create a child scope class if somebody asks for one,
|
||||
// but cache it to allow the VM to optimize lookups.
|
||||
if (!this.$$childScopeClass) {
|
||||
this.$$childScopeClass = function() {
|
||||
this.$$watchers = this.$$nextSibling =
|
||||
this.$$childHead = this.$$childTail = null;
|
||||
this.$$listeners = {};
|
||||
this.$$listenerCount = {};
|
||||
this.$id = nextUid();
|
||||
this.$$childScopeClass = null;
|
||||
};
|
||||
this.$$childScopeClass.prototype = this;
|
||||
}
|
||||
child = new this.$$childScopeClass();
|
||||
}
|
||||
child['this'] = child;
|
||||
child.$$listeners = {};
|
||||
child.$$listenerCount = {};
|
||||
child.$parent = this;
|
||||
child.$$watchers = child.$$nextSibling = child.$$childHead = child.$$childTail = null;
|
||||
child.$$prevSibling = this.$$childTail;
|
||||
if (this.$$childHead) {
|
||||
this.$$childTail.$$nextSibling = child;
|
||||
|
||||
Reference in New Issue
Block a user