From 136c028d29fc859625545bd703ed8c4ebfbe0b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 7 Apr 2013 17:36:35 -0700 Subject: [PATCH] Increase performance of Style getters / setters. --- src/style/Style.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/style/Style.js b/src/style/Style.js index 19c269ab..c0a58621 100644 --- a/src/style/Style.js +++ b/src/style/Style.js @@ -32,14 +32,6 @@ var Style = Base.extend({ }, this); }, - /** - * Returns the children to be used to unify style attributes, if any. - */ - _getChildren: function() { - // Only unify styles on children of Group items, excluding CompoundPath. - return this._item instanceof Group && this._item._children; - }, - statics: { create: function(item) { var style = Base.create(this); @@ -73,10 +65,13 @@ var Style = Base.extend({ // Simply extend src with these getters and setters, to be // injected into this class using this.base() further down. src[set] = function(value) { - var children = this._getChildren(); + var children = this._item && this._item._children; // Clone color objects since they reference their owner value = isColor ? Color.read(arguments, 0, 0, true) : value; - if (children && children.length > 0) { + // Only unify styles on children of Groups, excluding + // CompoundPaths. + if (children && children.length > 0 + && this._item._type !== 'compound-path') { for (var i = 0, l = children.length; i < l; i++) children[i][styleKey][set](value); } else { @@ -99,11 +94,12 @@ var Style = Base.extend({ } }; src[get] = function() { - var children = this._getChildren(), - style; + var style, + children = this._item && this._item._children; // If this item has children, walk through all of them and // see if they all have the same style. - if (!children || children.length === 0) + if (!children || children.length === 0 + || this._item._type === 'compound-path') return this['_' + key]; for (var i = 0, l = children.length; i < l; i++) { var childStyle = children[i][styleKey][get]();