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

perf(scope): misc optims #610

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 21 additions & 37 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 @@ -278,12 +271,14 @@ class Scope {
var child = new Scope(childContext, rootScope, this,
_readWriteGroup.newGroup(childContext),
_readOnlyGroup.newGroup(childContext));
var next = null;
var prev = _childTail;
child._next = next;
child._prev = prev;
if (prev == null) _childHead = child; else prev._next = child;
if (next == null) _childTail = child; else next._prev = child;
if (prev == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the original code much more readable. Can you revert this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in the last commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops already merged... I'll re-submit the optim as it seems to have been reverted altogether with the style !

_childHead = child;
} else {
prev._next = child;
}
_childTail = child;
return child;
}

Expand All @@ -292,20 +287,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 +343,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