Replace delete in favor of setting to undefined to prevent V8 deoptimization.

This commit is contained in:
Jürg Lehni 2013-12-17 23:27:48 +01:00
parent 99d7b5cfdb
commit 3dbad9c477
10 changed files with 21 additions and 24 deletions

View file

@ -880,7 +880,7 @@ var LinkedRectangle = Rectangle.extend({
// afterwards here, only once per change. // afterwards here, only once per change.
this._dontNotify = true; this._dontNotify = true;
proto[name].apply(this, arguments); proto[name].apply(this, arguments);
delete this._dontNotify; this._dontNotify = false;
this._owner[this._setter](this); this._owner[this._setter](this);
}; };
}, /** @lends Rectangle# */{ }, /** @lends Rectangle# */{

View file

@ -191,9 +191,9 @@ Base.inject(/** @lends Base# */{
// Have arguments.__read point to the amount of args read in the // Have arguments.__read point to the amount of args read in the
// last read() call // last read() call
list.__read = obj.__read; list.__read = obj.__read;
delete obj.__read; obj.__read = undefined;
if (options) if (options)
delete obj.__options; obj.__options = undefined;
} }
return obj; return obj;
}, },
@ -491,9 +491,9 @@ Base.inject(/** @lends Base# */{
if (items) if (items)
args.push.apply(args, items); args.push.apply(args, items);
var removed = list.splice.apply(list, args); 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++) 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. // Adjust the indices of the items above.
for (var i = index + amount, l = list.length; i < l; i++) for (var i = index + amount, l = list.length; i < l; i++)
list[i]._index = i; list[i]._index = i;

View file

@ -106,7 +106,7 @@ var Group = Item.extend(/** @lends Group# */{
} }
if (flags & (/*#=*/ ChangeFlag.HIERARCHY | /*#=*/ ChangeFlag.CLIPPING)) { if (flags & (/*#=*/ ChangeFlag.HIERARCHY | /*#=*/ ChangeFlag.CLIPPING)) {
// Clear cached clip item whenever hierarchy changes // Clear cached clip item whenever hierarchy changes
delete this._clipItem; this._clipItem = undefined;
} }
}, },

View file

@ -103,9 +103,9 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
_changed: function _changed(flags) { _changed: function _changed(flags) {
_changed.base.call(this, flags); _changed.base.call(this, flags);
// Delete cached native Path // Clear cached native Path
if (flags & (/*#=*/ ChangeFlag.HIERARCHY | /*#=*/ ChangeFlag.GEOMETRY)) if (flags & (/*#=*/ ChangeFlag.HIERARCHY | /*#=*/ ChangeFlag.GEOMETRY))
delete this._currentPath; this._currentPath = undefined;
}, },
insertChildren: function insertChildren(index, items, _preserve) { insertChildren: function insertChildren(index, items, _preserve) {

View file

@ -98,8 +98,7 @@ var Curve = Base.extend(/** @lends Curve# */{
_changed: function() { _changed: function() {
// Clear cached values. // Clear cached values.
delete this._length; this._length = this._bounds = undefined;
delete this._bounds;
}, },
/** /**

View file

@ -135,11 +135,10 @@ var Path = PathItem.extend(/** @lends Path# */{
_changed: function _changed(flags) { _changed: function _changed(flags) {
_changed.base.call(this, flags); _changed.base.call(this, flags);
if (flags & /*#=*/ ChangeFlag.GEOMETRY) { if (flags & /*#=*/ ChangeFlag.GEOMETRY) {
// Delete cached native Path // Clear cached native Path
delete (this._compound ? this._parent : this)._currentPath; (this._compound ? this._parent : this)._currentPath = undefined;
delete this._length;
// Clockwise state becomes undefined as soon as geometry changes. // Clockwise state becomes undefined as soon as geometry changes.
delete this._clockwise; this._length = this._clockwise = undefined;
// Curves are no longer valid // Curves are no longer valid
if (this._curves) { if (this._curves) {
for (var i = 0, l = this._curves.length; i < l; i++) 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) { } else if (flags & /*#=*/ ChangeFlag.STROKE) {
// TODO: We could preserve the purely geometric bounds that are not // TODO: We could preserve the purely geometric bounds that are not
// affected by stroke: _bounds.bounds and _bounds.handleBounds // 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._segments.length = 0;
this._selectedSegmentState = 0; this._selectedSegmentState = 0;
// Calculate new curves next time we call getCurves() // Calculate new curves next time we call getCurves()
delete this._curves; this._curves = undefined;
this._add(Segment.readAll(segments)); this._add(Segment.readAll(segments));
if (fullySelected) if (fullySelected)
this.setFullySelected(true); this.setFullySelected(true);
@ -701,8 +700,7 @@ var Path = PathItem.extend(/** @lends Path# */{
if (segment._selectionState) if (segment._selectionState)
this._updateSelection(segment, segment._selectionState, 0); this._updateSelection(segment, segment._selectionState, 0);
// Clear the indices and path references of the removed segments // Clear the indices and path references of the removed segments
delete segment._index; segment._index = segment._path = null;
delete segment._path;
} }
// Adjust the indices of the segments above. // Adjust the indices of the segments above.
for (var i = from, l = segments.length; i < l; i++) for (var i = from, l = segments.length; i < l; i++)
@ -1144,7 +1142,7 @@ var Path = PathItem.extend(/** @lends Path# */{
segment._index = i; segment._index = i;
} }
// Clear curves since it all has changed. // Clear curves since it all has changed.
delete this._curves; this._curves = null;
// Flip clockwise state if it's defined // Flip clockwise state if it's defined
if (this._clockwise !== undefined) if (this._clockwise !== undefined)
this._clockwise = !this._clockwise; this._clockwise = !this._clockwise;

View file

@ -192,7 +192,7 @@ PathItem.inject(new function() {
path.remove(); path.remove();
} }
} }
// Delete the proxies // Remove the proxies
path1.remove(); path1.remove();
path2.remove(); path2.remove();
// And then, we are done. // And then, we are done.

View file

@ -121,7 +121,7 @@ var Symbol = Base.extend(/** @lends Symbol# */{
item = item.clone(); item = item.clone();
// Remove previous definition's reference to this symbol // Remove previous definition's reference to this symbol
if (this._definition) if (this._definition)
delete this._definition._parentSymbol; this._definition._parentSymbol = null;
this._definition = item; this._definition = item;
// Remove item from DOM, as it's embedded in Symbol now. // Remove item from DOM, as it's embedded in Symbol now.
item.remove(); item.remove();

View file

@ -113,7 +113,7 @@ var Gradient = Base.extend(/** @lends Gradient# */{
if (index != -1) { if (index != -1) {
this._owners.splice(index, 1); this._owners.splice(index, 1);
if (this._owners.length === 0) 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. // this gradient as their owner.
if (this.stops) { if (this.stops) {
for (var i = 0, l = this._stops.length; i < l; i++) 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) if (stops.length < 2)
throw new Error( throw new Error(

View file

@ -147,7 +147,7 @@ var Style = Base.extend(new function() {
if (old != value) { if (old != value) {
if (isColor) { if (isColor) {
if (old) if (old)
delete old._owner; old._owner = undefined;
if (value && value.constructor === Color) { if (value && value.constructor === Color) {
// Clone color if it already has an owner. // Clone color if it already has an owner.
// NOTE: If value is not a Color, it is only // NOTE: If value is not a Color, it is only