mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Implement a row of simple optimizations to increase performance of Item constructors.
This commit is contained in:
parent
232ea221b4
commit
218732e320
8 changed files with 14 additions and 10 deletions
|
@ -70,7 +70,7 @@ this.Base = Base.inject(/** @lends Base# */{
|
|||
* @return {Boolean} {@true if the object is a plain object}
|
||||
*/
|
||||
_set: function(props) {
|
||||
if (Base.isPlainObject(props)) {
|
||||
if (props && Base.isPlainObject(props)) {
|
||||
for (var key in props)
|
||||
if (props.hasOwnProperty(key) && key in this)
|
||||
this[key] = props[key];
|
||||
|
|
|
@ -93,7 +93,7 @@ var Group = this.Group = Item.extend(/** @lends Group# */{
|
|||
// Allow Group to have children and named children
|
||||
this._children = [];
|
||||
this._namedChildren = {};
|
||||
if (!this._set(arg))
|
||||
if (arg && !this._set(arg))
|
||||
this.addChildren(Array.isArray(arg) ? arg : arguments);
|
||||
},
|
||||
|
||||
|
|
|
@ -235,7 +235,8 @@ var Item = this.Item = Base.extend(Callback, {
|
|||
* });
|
||||
*/
|
||||
set: function(props) {
|
||||
this._set(props);
|
||||
if (props)
|
||||
this._set(props);
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
|
|||
this.base(arg1 !== undefined && Point.read(arguments, 1));
|
||||
// If we can handle setting properties through object literal, we're all
|
||||
// set. Otherwise we need to set symbol.
|
||||
if (!this._set(arg0))
|
||||
if (arg0 && !this._set(arg0))
|
||||
this.setSymbol(arg0 instanceof Symbol ? arg0 : new Symbol(arg0));
|
||||
},
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
|
|||
// CompoundPath has children and supports named children.
|
||||
this._children = [];
|
||||
this._namedChildren = {};
|
||||
if (!this._set(arg))
|
||||
if (arg && !this._set(arg))
|
||||
this.addChildren(Array.isArray(arg) ? arg : arguments);
|
||||
},
|
||||
|
||||
|
|
|
@ -13,7 +13,11 @@
|
|||
Path.inject({ statics: new function() {
|
||||
|
||||
function createPath(args) {
|
||||
return new Path().set(Base.getNamed(args));
|
||||
var path = new Path(),
|
||||
named = Base.getNamed(args);
|
||||
if (named)
|
||||
path._set(named);
|
||||
return path;
|
||||
}
|
||||
|
||||
function createRectangle(/* rect */) {
|
||||
|
|
|
@ -86,7 +86,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
? arguments
|
||||
: null;
|
||||
this.setSegments(segments || []);
|
||||
if (!segments)
|
||||
if (arg && !segments)
|
||||
this._set(arg);
|
||||
},
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
|||
this._paragraphStyle = ParagraphStyle.create(this);
|
||||
// See if a point is passed, and if so, pass it on to base(). If not, it
|
||||
// might be a properties object literal for #setPropeties() at the end.
|
||||
var hasProperties = Base.isPlainObject(arg)
|
||||
var hasProperties = arg && Base.isPlainObject(arg)
|
||||
&& arg.x === undefined && arg.y === undefined;
|
||||
this.base(hasProperties ? null : Point.read(arguments));
|
||||
// No need to call setStyle(), since base() handles this already.
|
||||
|
@ -49,9 +49,8 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
|||
this.setParagraphStyle();
|
||||
this._content = '';
|
||||
this._lines = [];
|
||||
if (hasProperties) {
|
||||
if (hasProperties)
|
||||
this._set(arg);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue