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

Commit

Permalink
perf(scope): misc optimizations
Browse files Browse the repository at this point in the history
Closes #610
  • Loading branch information
vicb authored and mhevery committed Feb 26, 2014
1 parent 271ecec commit 7f36a8e
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ class ScopeEvent {
Scope _currentScope;

/**
* true or false depending on if stopPropagation() was executed.
* true or false depending on if [stopPropagation] was executed.
*/
bool get propagationStopped => _propagationStopped;
bool _propagationStopped = false;

/**
* true or false depending on if preventDefault() was executed.
* true or false depending on if [preventDefault] was executed.
*/
bool get defaultPrevented => _defaultPrevented;
bool _defaultPrevented = false;

/**
** [name] - The name of the scope event.
** [targetScope] - The destination scope that is listening on the event.
* [name] - The name of the scope event.
* [targetScope] - The destination scope that is listening on the event.
*/
ScopeEvent(this.name, this.targetScope, this.data);

Expand Down Expand Up @@ -157,11 +157,8 @@ class Scope {
*/
bool get isDestroyed {
var scope = this;
var root = rootScope;
while(scope != null) {
if (scope == root) {
return false;
}
if (scope == rootScope) return false;
scope = scope._parentScope;
}
return true;
Expand Down Expand Up @@ -213,11 +210,7 @@ class Scope {
};
} else if (expression.startsWith(':')) {
expression = expression.substring(1);
fn = (value, last) {
if (value != null) {
return reactionFn(value, last);
}
};
fn = (value, last) => value == null ? null : reactionFn(value, last);
}
ast = rootScope._astParser(expression, context: context, filters: filters);
} else {
Expand Down Expand Up @@ -292,20 +285,18 @@ class Scope {
broadcast(ScopeEvent.DESTROY);
_Streams.destroy(this);

var prev = _prev;
var next = _next;
if (prev == null) {
_parentScope._childHead = next;
if (_prev == null) {
_parentScope._childHead = _next;
} else {
prev._next = next;
_prev._next = _next;
}
if (next == null) {
_parentScope._childTail = prev;
if (_next == null) {
_parentScope._childTail = _prev;
} else {
next._prev = prev;
_next._prev = _prev;
}

this._next = this._prev = null;
_next = _prev = null;

_readWriteGroup.remove();
_readOnlyGroup.remove();
Expand Down Expand Up @@ -350,17 +341,8 @@ class Scope {
}
}

_mapEqual(Map a, Map b) {
if (a.length == b.length) {
var equal = true;
a.forEach((k, v) {
equal = equal && b.containsKey(k) && v == b[k];
});
return equal;
} else {
return false;
}
}
_mapEqual(Map a, Map b) => a.length == b.length &&
a.keys.every((k) => b.containsKey(k) && a[k] == b[k]);

class RootScope extends Scope {
static final STATE_APPLY = 'apply';
Expand Down

0 comments on commit 7f36a8e

Please sign in to comment.