Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 7f36a8e

Browse files
vicbmhevery
authored andcommitted
perf(scope): misc optimizations
Closes #610
1 parent 271ecec commit 7f36a8e

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

lib/core/scope.dart

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ class ScopeEvent {
4040
Scope _currentScope;
4141

4242
/**
43-
* true or false depending on if stopPropagation() was executed.
43+
* true or false depending on if [stopPropagation] was executed.
4444
*/
4545
bool get propagationStopped => _propagationStopped;
4646
bool _propagationStopped = false;
4747

4848
/**
49-
* true or false depending on if preventDefault() was executed.
49+
* true or false depending on if [preventDefault] was executed.
5050
*/
5151
bool get defaultPrevented => _defaultPrevented;
5252
bool _defaultPrevented = false;
5353

5454
/**
55-
** [name] - The name of the scope event.
56-
** [targetScope] - The destination scope that is listening on the event.
55+
* [name] - The name of the scope event.
56+
* [targetScope] - The destination scope that is listening on the event.
5757
*/
5858
ScopeEvent(this.name, this.targetScope, this.data);
5959

@@ -157,11 +157,8 @@ class Scope {
157157
*/
158158
bool get isDestroyed {
159159
var scope = this;
160-
var root = rootScope;
161160
while(scope != null) {
162-
if (scope == root) {
163-
return false;
164-
}
161+
if (scope == rootScope) return false;
165162
scope = scope._parentScope;
166163
}
167164
return true;
@@ -213,11 +210,7 @@ class Scope {
213210
};
214211
} else if (expression.startsWith(':')) {
215212
expression = expression.substring(1);
216-
fn = (value, last) {
217-
if (value != null) {
218-
return reactionFn(value, last);
219-
}
220-
};
213+
fn = (value, last) => value == null ? null : reactionFn(value, last);
221214
}
222215
ast = rootScope._astParser(expression, context: context, filters: filters);
223216
} else {
@@ -292,20 +285,18 @@ class Scope {
292285
broadcast(ScopeEvent.DESTROY);
293286
_Streams.destroy(this);
294287

295-
var prev = _prev;
296-
var next = _next;
297-
if (prev == null) {
298-
_parentScope._childHead = next;
288+
if (_prev == null) {
289+
_parentScope._childHead = _next;
299290
} else {
300-
prev._next = next;
291+
_prev._next = _next;
301292
}
302-
if (next == null) {
303-
_parentScope._childTail = prev;
293+
if (_next == null) {
294+
_parentScope._childTail = _prev;
304295
} else {
305-
next._prev = prev;
296+
_next._prev = _prev;
306297
}
307298

308-
this._next = this._prev = null;
299+
_next = _prev = null;
309300

310301
_readWriteGroup.remove();
311302
_readOnlyGroup.remove();
@@ -350,17 +341,8 @@ class Scope {
350341
}
351342
}
352343

353-
_mapEqual(Map a, Map b) {
354-
if (a.length == b.length) {
355-
var equal = true;
356-
a.forEach((k, v) {
357-
equal = equal && b.containsKey(k) && v == b[k];
358-
});
359-
return equal;
360-
} else {
361-
return false;
362-
}
363-
}
344+
_mapEqual(Map a, Map b) => a.length == b.length &&
345+
a.keys.every((k) => b.containsKey(k) && a[k] == b[k]);
364346

365347
class RootScope extends Scope {
366348
static final STATE_APPLY = 'apply';

0 commit comments

Comments
 (0)