flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
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
Date Sun, 21 Jun 2015 21:16:04 GMT
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 <mihaic@apache.org>
Authored: Sun Jun 21 21:29:42 2015 +0100
Committer: Mihai Chira <mihaic@apache.org>
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


Mime
View raw message