From ecdcbf7d9b2d8c5607b9ebbb9d3bf5fe502b6666 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Wed, 26 Aug 2009 19:59:52 +0000 Subject: [PATCH] Changed getIntersectionList for minor performance improvement git-svn-id: http://svg-edit.googlecode.com/svn/trunk@478 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 23eedae8..f79f28d3 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -569,6 +569,8 @@ function SvgCanvas(c) var undoStackPointer = 0; var undoStack = []; + var curBBoxes = []; + // This method sends back an array or a NodeList full of elements that // intersect the multi-select rubber-band-box. // @@ -581,29 +583,38 @@ function SvgCanvas(c) var getIntersectionList = function(rect) { if (rubberBox == null) { return null; } + if(!curBBoxes.length) { + // Cache all bboxes + + var nodes = svgroot.childNodes; + var i = svgroot.childNodes.length; + + while (i--) { + // need to do this since the defs has no bbox and causes an exception + // to be thrown in Mozilla + try { + if (nodes[i].id != "selectorParentGroup" && canvas.getBBox(nodes[i])) { + curBBoxes.push({'elem':nodes[i], 'bbox':canvas.getBBox(nodes[i])}); + } + } catch(e) { + // do nothing, this element did not have a bbox + } + } + } + var resultList = null; try { resultList = svgroot.getIntersectionList(rect, null); } catch(e) { } - if (resultList == null || typeof(resultList.item) != "function") - { + if (resultList == null || typeof(resultList.item) != "function") { resultList = []; var rubberBBox = rubberBox.getBBox(); - var nodes = svgroot.childNodes; - var i = svgroot.childNodes.length; + var i = curBBoxes.length; while (i--) { - // need to do this since the defs has no bbox and causes an exception - // to be thrown in Mozilla - try { - if (nodes[i].id != "selectorParentGroup" && - Utils.rectsIntersect(rubberBBox, canvas.getBBox(nodes[i]))) - { - resultList.push(nodes[i]); - } - } catch(e) { - // do nothing, this element did not have a bbox + if (Utils.rectsIntersect(rubberBBox, curBBoxes[i].bbox)) { + resultList.push(curBBoxes[i].elem); } } } @@ -1765,6 +1776,7 @@ function SvgCanvas(c) case "multiselect": if (rubberBox != null) { rubberBox.setAttribute("display", "none"); + curBBoxes = []; } current_mode = "select"; case "select":