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

Commit abdebc8

Browse files
committed
perf($rootScope): moving internal queues out of the Scope instances
1 parent 5b426f6 commit abdebc8

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.$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.
@@ -692,8 +686,6 @@ function $RootScopeProvider(){
692686
$digest: function() {
693687
var watch, value, last,
694688
watchers,
695-
asyncQueue = this.$$asyncQueue,
696-
postDigestQueue = this.$$postDigestQueue,
697689
length,
698690
dirty, ttl = TTL,
699691
next, current, target = this,
@@ -870,9 +862,6 @@ function $RootScopeProvider(){
870862
this.$parent = this.$$nextSibling = this.$$prevSibling = this.$$childHead =
871863
this.$$childTail = this.$root = this.$$watchers = this.$$listeners = null;
872864

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

953-
this.$$asyncQueue.push({scope: this, expression: expr});
942+
asyncQueue.push({scope: this, expression: expr});
954943
},
955944

956945
$$postDigest : function(fn) {
957-
this.$$postDigestQueue.push(fn);
946+
postDigestQueue.push(fn);
958947
},
959948

960949
/**
@@ -1038,7 +1027,7 @@ function $RootScopeProvider(){
10381027
*/
10391028
$applyAsync: function(expr) {
10401029
var scope = this;
1041-
expr && $rootScope.$$applyAsyncQueue.push($applyAsyncExpression);
1030+
expr && applyAsyncQueue.push($applyAsyncExpression);
10421031
scheduleApplyAsync();
10431032

10441033
function $applyAsyncExpression() {
@@ -1250,6 +1239,10 @@ function $RootScopeProvider(){
12501239

12511240
var $rootScope = new Scope();
12521241

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

12551248

@@ -1283,10 +1276,9 @@ function $RootScopeProvider(){
12831276
function initWatchVal() {}
12841277

12851278
function flushApplyAsync() {
1286-
var queue = $rootScope.$$applyAsyncQueue;
1287-
while (queue.length) {
1279+
while (applyAsyncQueue.length) {
12881280
try {
1289-
queue.shift()();
1281+
applyAsyncQueue.shift()();
12901282
} catch(e) {
12911283
$exceptionHandler(e);
12921284
}

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)