Repository: flex-sdk Updated Branches: refs/heads/develop 87e399b79 -> 74ec7c729
ArrayList performance optimization. Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/74ec7c72 Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/74ec7c72 Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/74ec7c72 Branch: refs/heads/develop Commit: 74ec7c72989d2fb406e5df52cf60b6ec45165159 Parents: 87e399b Author: shane.doolan <[email protected]> Authored: Tue Feb 24 09:44:18 2015 +1100 Committer: piotrz <[email protected]> Committed: Thu Feb 26 21:46:53 2015 +0100 ---------------------------------------------------------------------- .../org/apache/flex/collections/ArrayList.as | 35 ++++++++++++++++--- .../framework/src/mx/collections/ArrayList.as | 36 +++++++++++++++++--- 2 files changed, 62 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/74ec7c72/frameworks/projects/apache/src/org/apache/flex/collections/ArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/apache/src/org/apache/flex/collections/ArrayList.as b/frameworks/projects/apache/src/org/apache/flex/collections/ArrayList.as index 93b821a..a1ea7b4 100644 --- a/frameworks/projects/apache/src/org/apache/flex/collections/ArrayList.as +++ b/frameworks/projects/apache/src/org/apache/flex/collections/ArrayList.as @@ -397,14 +397,26 @@ public class ArrayList extends EventDispatcher */ public function addItemAt(item:Object, index:int):void { - if (index < 0 || index > length) + const spliceUpperBound:int = length; + + if (index < spliceUpperBound && index > 0) + { + source.splice(index, 0, item); + } + else if (index == spliceUpperBound) + { + source.push(item); + } + else if (index == 0) + { + source.unshift(item); + } + else { var message:String = resourceManager.getString( "collections", "outOfBounds", [ index ]); throw new RangeError(message); } - - source.splice(index, 0, item); startTrackUpdates(item); internalDispatchEvent(CollectionEventKind.ADD, item, index); @@ -495,7 +507,22 @@ public class ArrayList extends EventDispatcher */ public function removeItemAt(index:int):Object { - if (index < 0 || index >= length) + const spliceUpperBound:int = length - 1; + var removed:Object; + + if (index > 0 && index < spliceUpperBound) + { + removed = source.splice(index, 1)[0]; + } + else if (index == spliceUpperBound) + { + removed = source.pop(); + } + else if (index == 0) + { + removed = source.shift(); + } + else { var message:String = resourceManager.getString( "collections", "outOfBounds", [ index ]); http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/74ec7c72/frameworks/projects/framework/src/mx/collections/ArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/src/mx/collections/ArrayList.as b/frameworks/projects/framework/src/mx/collections/ArrayList.as index 79545d3..3051b50 100644 --- a/frameworks/projects/framework/src/mx/collections/ArrayList.as +++ b/frameworks/projects/framework/src/mx/collections/ArrayList.as @@ -410,14 +410,26 @@ public class ArrayList extends EventDispatcher */ public function addItemAt(item:Object, index:int):void { - if (index < 0 || index > length) + const spliceUpperBound:int = length; + + if (index < spliceUpperBound && index > 0) + { + source.splice(index, 0, item); + } + else if (index == spliceUpperBound) + { + source.push(item); + } + else if (index == 0) + { + source.unshift(item); + } + else { var message:String = resourceManager.getString( "collections", "outOfBounds", [ index ]); throw new RangeError(message); } - - source.splice(index, 0, item); startTrackUpdates(item); internalDispatchEvent(CollectionEventKind.ADD, item, index); @@ -526,14 +538,28 @@ public class ArrayList extends EventDispatcher */ public function removeItemAt(index:int):Object { - if (index < 0 || index >= length) + const spliceUpperBound:int = length - 1; + var removed:Object; + + if (index > 0 && index < spliceUpperBound) + { + removed = source.splice(index, 1)[0]; + } + else if (index == spliceUpperBound) + { + removed = source.pop(); + } + else if (index == 0) + { + removed = source.shift(); + } + else { var message:String = resourceManager.getString( "collections", "outOfBounds", [ index ]); throw new RangeError(message); } - var removed:Object = source.splice(index, 1)[0]; stopTrackUpdates(removed); internalDispatchEvent(CollectionEventKind.REMOVE, removed, index); return removed;
