Skip to content

Commit

Permalink
Use for..in instead of .forEach, it is much more efficient in dart2js
Browse files Browse the repository at this point in the history
  • Loading branch information
travissanderson-wf committed Dec 13, 2018
1 parent e2c4a8b commit b82cc95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions lib/src/r_tree/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ abstract class Node<E> extends RTreeContributor {

_minimumBoundingRect = null;

children.forEach((RTreeContributor child) {
for (var child in children) {
include(child);
});
}
}

Node<E> splitIfNecessary() => size > branchFactor ? _split() : null;
Expand All @@ -94,7 +94,7 @@ abstract class Node<E> extends RTreeContributor {
}

_reassignRemainingChildren(List<RTreeContributor> remainingChildren, Node<E> splitNode) {
remainingChildren.forEach((RTreeContributor child) {
for (var child in remainingChildren) {
num thisExpansionCost = expansionCost(child);
num splitExpansionCost = splitNode.expansionCost(child);

Expand All @@ -107,7 +107,7 @@ abstract class Node<E> extends RTreeContributor {
} else {
splitNode.addChild(child);
}
});
}
}

_Seeds _pickSeeds() {
Expand All @@ -119,12 +119,12 @@ abstract class Node<E> extends RTreeContributor {
RTreeContributor topmost = children.elementAt(0);
RTreeContributor bottommost = children.elementAt(0);

children.forEach((RTreeContributor child) {
for (var child in children) {
if (child.rect.right < leftmost.rect.right) leftmost = child;
if (child.rect.left > rightmost.rect.left) rightmost = child;
if (child.rect.top > bottommost.rect.top) bottommost = child;
if (child.rect.bottom < topmost.rect.bottom) topmost = child;
});
}

RTreeContributor a, b, c, d;
if (_horizontalDifference(leftmost, rightmost) > _verticalDifference(topmost, bottommost)) {
Expand Down
16 changes: 8 additions & 8 deletions lib/src/r_tree/non_leaf_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class NonLeafNode<E> extends Node<E> {
Iterable<RTreeDatum<E>> search(Rectangle searchRect) {
List<RTreeDatum<E>> overlappingLeafs = [];

_childNodes.forEach((Node<E> childNode) {
for (var childNode in _childNodes) {
if (childNode.overlaps(searchRect)) {
overlappingLeafs.addAll(childNode.search(searchRect));
}
});
}

return overlappingLeafs;
}
Expand All @@ -54,19 +54,19 @@ class NonLeafNode<E> extends Node<E> {
remove(RTreeDatum<E> item) {
List<Node<E>> childrenToRemove = [];

_childNodes.forEach((Node<E> childNode) {
for (var childNode in _childNodes) {
if (childNode.overlaps(item.rect)) {
childNode.remove(item);

if (childNode.size == 0) {
childrenToRemove.add(childNode);
}
}
});
}

childrenToRemove.forEach((Node<E> child) {
for (var child in childrenToRemove) {
removeChild(child);
});
}
}

addChild(Node<E> child) {
Expand All @@ -93,13 +93,13 @@ class NonLeafNode<E> extends Node<E> {
num tentativeCost;
Node<E> bestNode;

_childNodes.forEach((Node<E> child) {
for (var child in _childNodes) {
tentativeCost = child.expansionCost(item);
if (tentativeCost < bestCost) {
bestCost = tentativeCost;
bestNode = child;
}
});
}

return bestNode;
}
Expand Down

0 comments on commit b82cc95

Please sign in to comment.