From 98f7c020bd4b777a7e003041838ae4c772eadd53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 19 Apr 2013 19:27:02 -0700 Subject: [PATCH] Use Item#type instead of instanceof checks for better performance. --- src/item/Item.js | 2 +- src/svg/SvgImport.js | 2 +- src/tool/ToolEvent.js | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 1728d662..fcb8056c 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1779,7 +1779,7 @@ var Item = this.Item = Base.extend(Callback, { // Find group parents. Check for parent._parent, since don't want // top level layers, because they also inherit from Group if (parent._parent - && (parent instanceof Group || parent instanceof CompoundPath) + && /^(group|layer|compound-path)$/.test(parent._type) && item.isDescendant(parent)) return true; // Keep walking up otherwise diff --git a/src/svg/SvgImport.js b/src/svg/SvgImport.js index b32a897a..333d41dc 100644 --- a/src/svg/SvgImport.js +++ b/src/svg/SvgImport.js @@ -89,7 +89,7 @@ new function() { if (childNode.nodeType == 1 && (child = importSvg(childNode))) { // If adding CompoundPaths to other CompoundPaths, // we need to "unbox" them first: - if (clip && child instanceof CompoundPath) { + if (clip && child._type === 'compound-path') { item.addChildren(child.removeChildren()); child.remove(); } else if (!(child instanceof Symbol)) { diff --git a/src/tool/ToolEvent.js b/src/tool/ToolEvent.js index a64565be..72c0fead 100644 --- a/src/tool/ToolEvent.js +++ b/src/tool/ToolEvent.js @@ -181,10 +181,9 @@ var ToolEvent = this.ToolEvent = Event.extend(/** @lends ToolEvent# */{ var result = this.tool._scope.project.hitTest(this.getPoint()); if (result) { var item = result.item, - // Find group parent + // Find group parent, but exclude layers parent = item._parent; - while ((parent instanceof Group && !(parent instanceof Layer)) - || parent instanceof CompoundPath) { + while (/^(group|compound-path)$/.test(parent._type)) { item = parent; parent = parent._parent; }