From c8cbbeb2ada539d8c71a74a000b1eb329ad26bbe Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Wed, 17 Jun 2015 18:24:54 -0400 Subject: Optimize HandMorph::morphAtPointer a lot On large morph hierarchies this goes from ~85% CPU usage when moving the mouse around to ~5%. --- morphic.js | 41 ++++++++++++++++++++--------------------- 1 file 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); }; /* -- cgit v1.3.1