Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9FF37189C7 for ; Sun, 21 Jun 2015 21:15:59 +0000 (UTC) Received: (qmail 67561 invoked by uid 500); 21 Jun 2015 21:15:59 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 67506 invoked by uid 500); 21 Jun 2015 21:15:59 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 67348 invoked by uid 99); 21 Jun 2015 21:15:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Jun 2015 21:15:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 29E85E362D; Sun, 21 Jun 2015 21:15:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mihaic@apache.org To: commits@flex.apache.org Date: Sun, 21 Jun 2015 21:16:04 -0000 Message-Id: <625d74bfb8084f9ea88057bdf17d3a16@git.apache.org> In-Reply-To: <943d48fc0de842bc9b29c8e7043338b0@git.apache.org> References: <943d48fc0de842bc9b29c8e7043338b0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [6/6] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34854 spark.collections.Sort.sort() was very similar to mx.collections.Sort.sort(), with the only difference in the fact that the latter tried to use Array.sortOn when appropriate. So, to remove th FLEX-34854 spark.collections.Sort.sort() was very similar to mx.collections.Sort.sort(), with the only difference in the fact that the latter tried to use Array.sortOn when appropriate. So, to remove the duplication I introduced a new flag to the mx version called useSortOn, which the spark version defaults to false. This way I could completely remove spark.collections.Sort.sort() and reset a few members of the mx version as private, as before. Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/ece249f8 Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/ece249f8 Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/ece249f8 Branch: refs/heads/develop Commit: ece249f87ce2b9c605b4222ce65c4f8e754697b3 Parents: 3aacd76 Author: Mihai Chira Authored: Sun Jun 21 21:29:42 2015 +0100 Committer: Mihai Chira Committed: Sun Jun 21 21:29:42 2015 +0100 ---------------------------------------------------------------------- .../framework/src/mx/collections/Sort.as | 21 +++-- .../spark/src/spark/collections/Sort.as | 94 +------------------- 2 files changed, 18 insertions(+), 97 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/ece249f8/frameworks/projects/framework/src/mx/collections/Sort.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/src/mx/collections/Sort.as b/frameworks/projects/framework/src/mx/collections/Sort.as index 02cb41e..6348691 100644 --- a/frameworks/projects/framework/src/mx/collections/Sort.as +++ b/frameworks/projects/framework/src/mx/collections/Sort.as @@ -24,10 +24,13 @@ package mx.collections import flash.events.EventDispatcher; import mx.collections.errors.SortError; + import mx.core.mx_internal; import mx.resources.IResourceManager; import mx.resources.ResourceManager; import mx.utils.ObjectUtil; + use namespace mx_internal; + [DefaultProperty("fields")] [ResourceBundle("collections")] [Alternative(replacement="spark.collections.Sort", since="4.5")] @@ -211,9 +214,15 @@ public class Sort extends EventDispatcher implements ISort * @private * Used for accessing localized Error messages. */ - protected var resourceManager:IResourceManager = + private var resourceManager:IResourceManager = ResourceManager.getInstance(); + /** + * @private + * True if we should attempt to use Array.sortOn when possible. + */ + mx_internal var useSortOn:Boolean = true; + //-------------------------------------------------------------------------- // // Properties @@ -233,7 +242,7 @@ public class Sort extends EventDispatcher implements ISort /** * @private */ - protected var usingCustomCompareFunction:Boolean; + private var usingCustomCompareFunction:Boolean; [Inspectable(category="General")] @@ -655,7 +664,7 @@ public class Sort extends EventDispatcher implements ISort if (unique) { var uniqueRet2:Object; - if (sortArgs && fields.length == 1) + if (useSortOn && sortArgs && fields.length == 1) { uniqueRet2 = items.sortOn(sortArgs.fields[0], sortArgs.options[0] | Array.UNIQUESORT); } @@ -672,7 +681,7 @@ public class Sort extends EventDispatcher implements ISort } else { - if (sortArgs) + if (useSortOn && sortArgs) { items.sortOn(sortArgs.fields, sortArgs.options); } @@ -699,7 +708,7 @@ public class Sort extends EventDispatcher implements ISort * @private * Make sure all SortFields are ready to execute their comparators. */ - protected function initSortFields(item:Object, buildArraySortArgs:Boolean = false):Object + private function initSortFields(item:Object, buildArraySortArgs:Boolean = false):Object { var arraySortArgs:Object = null; var i:int; @@ -736,7 +745,7 @@ public class Sort extends EventDispatcher implements ISort * number of fields to check. We don't look at the actual values * to see if they match the actual sort. */ - protected function internalCompare(a:Object, b:Object, fields:Array = null):int + private function internalCompare(a:Object, b:Object, fields:Array = null):int { var result:int = 0; if (!_fields) http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/ece249f8/frameworks/projects/spark/src/spark/collections/Sort.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/spark/src/spark/collections/Sort.as b/frameworks/projects/spark/src/spark/collections/Sort.as index e0f1447..912e2dd 100644 --- a/frameworks/projects/spark/src/spark/collections/Sort.as +++ b/frameworks/projects/spark/src/spark/collections/Sort.as @@ -21,6 +21,8 @@ package spark.collections { import flash.events.Event; + + import mx.core.mx_internal; import mx.styles.IAdvancedStyleClient; import mx.collections.ISortField; import mx.collections.errors.SortError; @@ -254,6 +256,7 @@ public class Sort extends mx.collections.Sort implements IAdvancedStyleClient public function Sort(fields:Array = null, customCompareFunction:Function = null, unique:Boolean = false) { super(fields, customCompareFunction, unique); + mx_internal::useSortOn = false; } //-------------------------------------------------------------------------- @@ -352,97 +355,6 @@ public class Sort extends mx.collections.Sort implements IAdvancedStyleClient _advancedStyleClient.styleChanged(styleProp); } - - //-------------------------------------------------------------------------- - // - // Methods - // - //-------------------------------------------------------------------------- - - /** - * @inheritDoc - * - * @langversion 3.0 - * @playerversion Flash 10.1 - * @playerversion AIR 2.5 - * @productversion Flex 4.5 - */ - override public function sort(items:Array):void - { - if (!items || items.length <= 1) - { - return; - } - - if (usingCustomCompareFunction) - { - // bug 185872 - // the Sort.internalCompare function knows to use Sort._fields; that same logic - // needs to be part of calling a custom compareFunction. Of course, a user shouldn't - // be doing this -- so I wrap calls to compareFunction with _fields as the last parameter - const fixedCompareFunction:Function = - function (a:Object, b:Object):int - { - // append our fields to the call, since items.sort() won't - return compareFunction(a, b, fields); - }; - - var message:String; - - if (unique) - { - var uniqueRet1:Object = items.sort(fixedCompareFunction, Array.UNIQUESORT); - if (uniqueRet1 == 0) - { - message = resourceManager.getString( - "collections", "nonUnique"); - throw new SortError(message); - } - } - else - { - items.sort(fixedCompareFunction); - } - } - else - { - if (fields && fields.length > 0) - { - //doing the init value each time may be a little inefficient - //but allows for the data to change and the comparators - //to update correctly - //the sortArgs is an object that if non-null means - //we can use Array.sortOn which will be much faster - //than going through internalCompare. However - //if the Sort is supposed to be unique and fields.length > 1 - //we cannot use sortOn since it only tests uniqueness - //on the first field - initSortFields(items[0], true); - - if (unique) - { - var uniqueRet2:Object; - uniqueRet2 = items.sort(internalCompare, - Array.UNIQUESORT); - if (uniqueRet2 == 0) - { - message = resourceManager.getString( - "collections", "nonUnique"); - throw new SortError(message); - } - } - else - { - items.sort(internalCompare); - } - } - else - { - items.sort(internalCompare); - } - } - } - //-------------------------------------------------------------------------- // // Private Methods