Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit cac0273

Browse files
committed
perf($rootScope): moving internal queues out of the Scope instances
1 parent 13d1a36 commit cac0273

File tree

3 files changed

+13
-38
lines changed

3 files changed

+13
-38
lines changed

src/ng/rootScope.js

+11-19
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,8 @@ function $RootScopeProvider(){
130130
this.$$childHead = this.$$childTail = null;
131131
this['this'] = this.$root = this;
132132
this.$$destroyed = false;
133-
this.$$asyncQueue = [];
134-
this.$$postDigestQueue = [];
135133
this.$$listeners = this.$$listenerCount = null;
136134
this.$$isolateBindings = null;
137-
this.$$applyAsyncQueue = [];
138135
}
139136

140137
/**
@@ -192,9 +189,6 @@ function $RootScopeProvider(){
192189
if (isolate) {
193190
child = new Scope();
194191
child.$root = this.$root;
195-
// ensure that there is just one async queue per $rootScope and its children
196-
child.$$asyncQueue = this.$$asyncQueue;
197-
child.$$postDigestQueue = this.$$postDigestQueue;
198192
} else {
199193
// Only create a child scope class if somebody asks for one,
200194
// but cache it to allow the VM to optimize lookups.
@@ -693,8 +687,6 @@ function $RootScopeProvider(){
693687
$digest: function() {
694688
var watch, value, last,
695689
watchers,
696-
asyncQueue = this.$$asyncQueue,
697-
postDigestQueue = this.$$postDigestQueue,
698690
length,
699691
dirty, ttl = TTL,
700692
next, current, target = this,
@@ -871,9 +863,6 @@ function $RootScopeProvider(){
871863
this.$parent = this.$$nextSibling = this.$$prevSibling = this.$$childHead =
872864
this.$$childTail = this.$root = this.$$watchers = this.$$listeners = null;
873865

874-
// don't reset these to null in case some async task tries to register a listener/watch/task
875-
this.$$asyncQueue = this.$$postDigestQueue = [];
876-
877866
// prevent NPEs since these methods have references to properties we nulled out
878867
this.$destroy = this.$digest = this.$apply = noop;
879868
this.$on = this.$watch = this.$watchGroup = function() { return noop; };
@@ -943,19 +932,19 @@ function $RootScopeProvider(){
943932
$evalAsync: function(expr) {
944933
// if we are outside of an $digest loop and this is the first time we are scheduling async
945934
// task also schedule async auto-flush
946-
if (!$rootScope.$$phase && !$rootScope.$$asyncQueue.length) {
935+
if (!$rootScope.$$phase && !asyncQueue.length) {
947936
$browser.defer(function() {
948-
if ($rootScope.$$asyncQueue.length) {
937+
if (asyncQueue.length) {
949938
$rootScope.$digest();
950939
}
951940
});
952941
}
953942

954-
this.$$asyncQueue.push({scope: this, expression: expr});
943+
asyncQueue.push({scope: this, expression: expr});
955944
},
956945

957946
$$postDigest : function(fn) {
958-
this.$$postDigestQueue.push(fn);
947+
postDigestQueue.push(fn);
959948
},
960949

961950
/**
@@ -1039,7 +1028,7 @@ function $RootScopeProvider(){
10391028
*/
10401029
$applyAsync: function(expr) {
10411030
var scope = this;
1042-
expr && $rootScope.$$applyAsyncQueue.push($applyAsyncExpression);
1031+
expr && applyAsyncQueue.push($applyAsyncExpression);
10431032
scheduleApplyAsync();
10441033

10451034
function $applyAsyncExpression() {
@@ -1251,6 +1240,10 @@ function $RootScopeProvider(){
12511240

12521241
var $rootScope = new Scope();
12531242

1243+
var asyncQueue = [];
1244+
var postDigestQueue = [];
1245+
var applyAsyncQueue = [];
1246+
12541247
return $rootScope;
12551248

12561249

@@ -1284,10 +1277,9 @@ function $RootScopeProvider(){
12841277
function initWatchVal() {}
12851278

12861279
function flushApplyAsync() {
1287-
var queue = $rootScope.$$applyAsyncQueue;
1288-
while (queue.length) {
1280+
while (applyAsyncQueue.length) {
12891281
try {
1290-
queue.shift()();
1282+
applyAsyncQueue.shift()();
12911283
} catch(e) {
12921284
$exceptionHandler(e);
12931285
}

test/ng/directive/ngBindSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ describe('ngBind*', function() {
160160
it('should NOT set html for untrusted values', inject(function($rootScope, $compile) {
161161
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
162162
$rootScope.html = '<div onclick="">hello</div>';
163-
expect($rootScope.$digest).toThrow();
163+
expect(function() { $rootScope.$digest(); }).toThrow();
164164
}));
165165

166166
it('should NOT set html for wrongly typed values', inject(function($rootScope, $compile, $sce) {
167167
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
168168
$rootScope.html = $sce.trustAsCss('<div onclick="">hello</div>');
169-
expect($rootScope.$digest).toThrow();
169+
expect(function() { $rootScope.$digest(); }).toThrow();
170170
}));
171171

172172
it('should set html for trusted values', inject(function($rootScope, $compile, $sce) {

test/ng/rootScopeSpec.js

-17
Original file line numberDiff line numberDiff line change
@@ -1195,23 +1195,6 @@ describe('Scope', function() {
11951195
expect(child.log).toBe('child context');
11961196
}));
11971197

1198-
it('should operate only with a single queue across all child and isolate scopes', inject(function($rootScope) {
1199-
var childScope = $rootScope.$new();
1200-
var isolateScope = $rootScope.$new(true);
1201-
1202-
$rootScope.$evalAsync('rootExpression');
1203-
childScope.$evalAsync('childExpression');
1204-
isolateScope.$evalAsync('isolateExpression');
1205-
1206-
expect(childScope.$$asyncQueue).toBe($rootScope.$$asyncQueue);
1207-
expect(isolateScope.$$asyncQueue).toBe($rootScope.$$asyncQueue);
1208-
expect($rootScope.$$asyncQueue).toEqual([
1209-
{scope: $rootScope, expression: 'rootExpression'},
1210-
{scope: childScope, expression: 'childExpression'},
1211-
{scope: isolateScope, expression: 'isolateExpression'}
1212-
]);
1213-
}));
1214-
12151198

12161199
describe('auto-flushing when queueing outside of an $apply', function() {
12171200
var log, $rootScope, $browser;

0 commit comments

Comments
 (0)