Use Item#type instead of instanceof checks for better performance.

This commit is contained in:
Jürg Lehni 2013-04-19 19:27:02 -07:00
parent bf9acd4499
commit 98f7c020bd
3 changed files with 4 additions and 5 deletions

View file

@ -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

View file

@ -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)) {

View file

@ -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;
}