mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Replace delete in favor of setting to undefined to prevent V8 deoptimization.
This commit is contained in:
parent
99d7b5cfdb
commit
3dbad9c477
10 changed files with 21 additions and 24 deletions
|
@ -880,7 +880,7 @@ var LinkedRectangle = Rectangle.extend({
|
|||
// afterwards here, only once per change.
|
||||
this._dontNotify = true;
|
||||
proto[name].apply(this, arguments);
|
||||
delete this._dontNotify;
|
||||
this._dontNotify = false;
|
||||
this._owner[this._setter](this);
|
||||
};
|
||||
}, /** @lends Rectangle# */{
|
||||
|
|
|
@ -191,9 +191,9 @@ Base.inject(/** @lends Base# */{
|
|||
// Have arguments.__read point to the amount of args read in the
|
||||
// last read() call
|
||||
list.__read = obj.__read;
|
||||
delete obj.__read;
|
||||
obj.__read = undefined;
|
||||
if (options)
|
||||
delete obj.__options;
|
||||
obj.__options = undefined;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
|
@ -491,9 +491,9 @@ Base.inject(/** @lends Base# */{
|
|||
if (items)
|
||||
args.push.apply(args, items);
|
||||
var removed = list.splice.apply(list, args);
|
||||
// Delete the indices of the removed items
|
||||
// Erase the indices of the removed items
|
||||
for (var i = 0, l = removed.length; i < l; i++)
|
||||
delete removed[i]._index;
|
||||
removed[i]._index = undefined;
|
||||
// Adjust the indices of the items above.
|
||||
for (var i = index + amount, l = list.length; i < l; i++)
|
||||
list[i]._index = i;
|
||||
|
|
|
@ -106,7 +106,7 @@ var Group = Item.extend(/** @lends Group# */{
|
|||
}
|
||||
if (flags & (/*#=*/ ChangeFlag.HIERARCHY | /*#=*/ ChangeFlag.CLIPPING)) {
|
||||
// Clear cached clip item whenever hierarchy changes
|
||||
delete this._clipItem;
|
||||
this._clipItem = undefined;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -103,9 +103,9 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
|||
|
||||
_changed: function _changed(flags) {
|
||||
_changed.base.call(this, flags);
|
||||
// Delete cached native Path
|
||||
// Clear cached native Path
|
||||
if (flags & (/*#=*/ ChangeFlag.HIERARCHY | /*#=*/ ChangeFlag.GEOMETRY))
|
||||
delete this._currentPath;
|
||||
this._currentPath = undefined;
|
||||
},
|
||||
|
||||
insertChildren: function insertChildren(index, items, _preserve) {
|
||||
|
|
|
@ -98,8 +98,7 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
|
||||
_changed: function() {
|
||||
// Clear cached values.
|
||||
delete this._length;
|
||||
delete this._bounds;
|
||||
this._length = this._bounds = undefined;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -135,11 +135,10 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
_changed: function _changed(flags) {
|
||||
_changed.base.call(this, flags);
|
||||
if (flags & /*#=*/ ChangeFlag.GEOMETRY) {
|
||||
// Delete cached native Path
|
||||
delete (this._compound ? this._parent : this)._currentPath;
|
||||
delete this._length;
|
||||
// Clear cached native Path
|
||||
(this._compound ? this._parent : this)._currentPath = undefined;
|
||||
// Clockwise state becomes undefined as soon as geometry changes.
|
||||
delete this._clockwise;
|
||||
this._length = this._clockwise = undefined;
|
||||
// Curves are no longer valid
|
||||
if (this._curves) {
|
||||
for (var i = 0, l = this._curves.length; i < l; i++)
|
||||
|
@ -148,7 +147,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
} else if (flags & /*#=*/ ChangeFlag.STROKE) {
|
||||
// TODO: We could preserve the purely geometric bounds that are not
|
||||
// affected by stroke: _bounds.bounds and _bounds.handleBounds
|
||||
delete this._bounds;
|
||||
this._bounds = undefined;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -167,7 +166,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
this._segments.length = 0;
|
||||
this._selectedSegmentState = 0;
|
||||
// Calculate new curves next time we call getCurves()
|
||||
delete this._curves;
|
||||
this._curves = undefined;
|
||||
this._add(Segment.readAll(segments));
|
||||
if (fullySelected)
|
||||
this.setFullySelected(true);
|
||||
|
@ -701,8 +700,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
if (segment._selectionState)
|
||||
this._updateSelection(segment, segment._selectionState, 0);
|
||||
// Clear the indices and path references of the removed segments
|
||||
delete segment._index;
|
||||
delete segment._path;
|
||||
segment._index = segment._path = null;
|
||||
}
|
||||
// Adjust the indices of the segments above.
|
||||
for (var i = from, l = segments.length; i < l; i++)
|
||||
|
@ -1144,7 +1142,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
segment._index = i;
|
||||
}
|
||||
// Clear curves since it all has changed.
|
||||
delete this._curves;
|
||||
this._curves = null;
|
||||
// Flip clockwise state if it's defined
|
||||
if (this._clockwise !== undefined)
|
||||
this._clockwise = !this._clockwise;
|
||||
|
|
|
@ -192,7 +192,7 @@ PathItem.inject(new function() {
|
|||
path.remove();
|
||||
}
|
||||
}
|
||||
// Delete the proxies
|
||||
// Remove the proxies
|
||||
path1.remove();
|
||||
path2.remove();
|
||||
// And then, we are done.
|
||||
|
|
|
@ -121,7 +121,7 @@ var Symbol = Base.extend(/** @lends Symbol# */{
|
|||
item = item.clone();
|
||||
// Remove previous definition's reference to this symbol
|
||||
if (this._definition)
|
||||
delete this._definition._parentSymbol;
|
||||
this._definition._parentSymbol = null;
|
||||
this._definition = item;
|
||||
// Remove item from DOM, as it's embedded in Symbol now.
|
||||
item.remove();
|
||||
|
|
|
@ -113,7 +113,7 @@ var Gradient = Base.extend(/** @lends Gradient# */{
|
|||
if (index != -1) {
|
||||
this._owners.splice(index, 1);
|
||||
if (this._owners.length === 0)
|
||||
delete this._owners;
|
||||
this._owners = undefined;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -142,7 +142,7 @@ var Gradient = Base.extend(/** @lends Gradient# */{
|
|||
// this gradient as their owner.
|
||||
if (this.stops) {
|
||||
for (var i = 0, l = this._stops.length; i < l; i++)
|
||||
delete this._stops[i]._owner;
|
||||
this._stops[i]._owner = undefined;
|
||||
}
|
||||
if (stops.length < 2)
|
||||
throw new Error(
|
||||
|
|
|
@ -147,7 +147,7 @@ var Style = Base.extend(new function() {
|
|||
if (old != value) {
|
||||
if (isColor) {
|
||||
if (old)
|
||||
delete old._owner;
|
||||
old._owner = undefined;
|
||||
if (value && value.constructor === Color) {
|
||||
// Clone color if it already has an owner.
|
||||
// NOTE: If value is not a Color, it is only
|
||||
|
|
Loading…
Reference in a new issue