summaryrefslogtreecommitdiff
path: root/morphic.js
diff options
context:
space:
mode:
authorNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 18:24:54 -0400
committerNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 18:25:09 -0400
commitc8cbbeb2ada539d8c71a74a000b1eb329ad26bbe (patch)
tree4c136913b70dc700438347b7c378b39a7379ba6a /morphic.js
parent013e2740d853b660fbc48cda247b6fe711aecce9 (diff)
downloadsnap-c8cbbeb2ada539d8c71a74a000b1eb329ad26bbe.tar.gz
snap-c8cbbeb2ada539d8c71a74a000b1eb329ad26bbe.zip
Optimize HandMorph::morphAtPointer a lot
On large morph hierarchies this goes from ~85% CPU usage when moving the mouse around to ~5%.
Diffstat (limited to 'morphic.js')
-rw-r--r--morphic.js41
1 files changed, 20 insertions, 21 deletions
diff --git a/morphic.js b/morphic.js
index 029afd1..88f8c22 100644
--- a/morphic.js
+++ b/morphic.js
@@ -9392,28 +9392,27 @@ HandMorph.prototype.changed = function () {
// HandMorph navigation:
-HandMorph.prototype.morphAtPointer = function () {
- var morphs = this.world.allChildren().slice(0).reverse(),
- myself = this,
- result = null;
-
- morphs.forEach(function (m) {
- if (m.visibleBounds().containsPoint(myself.bounds.origin) &&
- result === null &&
- m.isVisible &&
- (m.noticesTransparentClick ||
- (!m.isTransparentAt(myself.bounds.origin))) &&
- (!(m instanceof ShadowMorph)) &&
- m.allParents().every(function (each) {
- return each.isVisible;
- })) {
- result = m;
- }
- });
- if (result !== null) {
- return result;
+Morph.prototype.topMorphAt = function (p) {
+ if (!this.isVisible) return null;
+ for (var c = this.children, i = c.length; i--;) {
+ var result = c[i].topMorphAt(p);
+ if (result) return result;
+ }
+ return this.bounds.containsPoint(p) ? this : null;
+};
+FrameMorph.prototype.topMorphAt = function (p) {
+ if (!(this.isVisible && this.bounds.containsPoint(p))) return null;
+ for (var c = this.children, i = c.length; i--;) {
+ var result = c[i].topMorphAt(p);
+ if (result) return result;
}
- return this.world;
+ return this;
+};
+ShadowMorph.prototype.topMorphAt = function () {
+ return null;
+};
+HandMorph.prototype.morphAtPointer = function () {
+ return this.world.topMorphAt(this.bounds.origin);
};
/*