flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcl...@apache.org
Subject [44/50] git commit: [flex-sdk] [refs/heads/master] - FLEX-33829 improve create UID performance and use
Date Mon, 21 Oct 2013 22:37:36 GMT
FLEX-33829 improve create UID performance and use


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/3f93971c
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/3f93971c
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/3f93971c

Branch: refs/heads/master
Commit: 3f93971c7fdde96dea0aacc3617728534976f13a
Parents: 0a418bd
Author: Justin Mclean <jmclean@apache.org>
Authored: Fri Oct 18 15:47:00 2013 +1100
Committer: Justin Mclean <jmclean@apache.org>
Committed: Fri Oct 18 15:47:00 2013 +1100

----------------------------------------------------------------------
 .../org/apache/flex/collections/ArrayList.as    |   4 +-
 .../org/apache/flex/collections/VectorList.as   |   4 +-
 .../framework/src/mx/collections/ArrayList.as   |   4 +-
 .../projects/framework/src/mx/utils/UIDUtil.as  | 108 ++++++++++---------
 4 files changed, 68 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3f93971c/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 3cce583..93b821a 100644
--- a/frameworks/projects/apache/src/org/apache/flex/collections/ArrayList.as
+++ b/frameworks/projects/apache/src/org/apache/flex/collections/ArrayList.as
@@ -120,7 +120,6 @@ public class ArrayList extends EventDispatcher
         disableEvents();
         this.source = source;
         enableEvents();
-        _uid = UIDUtil.createUID();
     }
     
     //--------------------------------------------------------------------------
@@ -257,6 +256,9 @@ public class ArrayList extends EventDispatcher
      */  
     public function get uid():String
     {
+		if (!_uid) {
+			_uid = UIDUtil.createUID();
+		}
         return _uid;
     }
     

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3f93971c/frameworks/projects/apache/src/org/apache/flex/collections/VectorList.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/apache/src/org/apache/flex/collections/VectorList.as b/frameworks/projects/apache/src/org/apache/flex/collections/VectorList.as
index 3d47c8c..5892935 100644
--- a/frameworks/projects/apache/src/org/apache/flex/collections/VectorList.as
+++ b/frameworks/projects/apache/src/org/apache/flex/collections/VectorList.as
@@ -110,7 +110,6 @@ public class VectorList extends EventDispatcher
         disableEvents();
         this.source = source;
         enableEvents();
-        _uid = UIDUtil.createUID();
     }
 
     /**
@@ -214,6 +213,9 @@ public class VectorList extends EventDispatcher
      */  
     public function get uid():String
     {
+		if (!_uid) {
+			_uid = UIDUtil.createUID();
+		}
         return _uid;
     }
     

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3f93971c/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 b207d42..1afa845 100644
--- a/frameworks/projects/framework/src/mx/collections/ArrayList.as
+++ b/frameworks/projects/framework/src/mx/collections/ArrayList.as
@@ -118,7 +118,6 @@ public class ArrayList extends EventDispatcher
         disableEvents();
         this.source = source;
         enableEvents();
-        _uid = UIDUtil.createUID();
     }
     
     //--------------------------------------------------------------------------
@@ -255,6 +254,9 @@ public class ArrayList extends EventDispatcher
      */  
     public function get uid():String
     {
+		if (!_uid) {
+			_uid = UIDUtil.createUID();
+		}
         return _uid;
     }
     

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3f93971c/frameworks/projects/framework/src/mx/utils/UIDUtil.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/utils/UIDUtil.as b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
index 4993563..20186e0 100644
--- a/frameworks/projects/framework/src/mx/utils/UIDUtil.as
+++ b/frameworks/projects/framework/src/mx/utils/UIDUtil.as
@@ -63,8 +63,18 @@ public class UIDUtil
      *  @private
      *  Char codes for 0123456789ABCDEF
      */
-    private static const ALPHA_CHAR_CODES:Array = [48, 49, 50, 51, 52, 53, 54, 
-        55, 56, 57, 65, 66, 67, 68, 69, 70];
+	private static const ALPHA_CHAR_CODES:Array = [48, 49, 50, 51, 52, 53, 54, 
+		55, 56, 57, 65, 66, 67, 68, 69, 70];
+	
+	private static const HEX_CHARS:String = "0123456789ABCDEF";
+	
+	private static var EMPTYUID:Array = [
+		'0','0','0','0','0','0','0','0',
+		'-','0','0','0','0',
+		'-','0','0','0','0',
+		'-','0','0','0','0',
+		'0','0','0','0','0','0','0','0','0','0','0','0'
+	];
 
     //--------------------------------------------------------------------------
     //
@@ -106,53 +116,53 @@ public class UIDUtil
      *  @playerversion AIR 1.1
      *  @productversion Flex 3
      */
-    public static function createUID():String
-    {
-        var uid:Array = new Array(36);
-        var index:int = 0;
-        
-        var i:int;
-        var j:int;
-        
-        for (i = 0; i < 8; i++)
-        {
-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-        }
-
-        for (i = 0; i < 3; i++)
-        {
-            uid[index++] = 45; // charCode for "-"
-            
-            for (j = 0; j < 4; j++)
-            {
-                uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-            }
-        }
-        
-        uid[index++] = 45; // charCode for "-"
-
-        var time:Number = new Date().getTime();
-        // Note: time is the number of milliseconds since 1970,
-        // which is currently more than one trillion.
-        // We use the low 8 hex digits of this number in the UID.
-        // Just in case the system clock has been reset to
-        // Jan 1-4, 1970 (in which case this number could have only
-        // 1-7 hex digits), we pad on the left with 7 zeros
-        // before taking the low digits.
-        var timeString:String = ("0000000" + time.toString(16).toUpperCase()).substr(-8);
-        
-        for (i = 0; i < 8; i++)
-        {
-            uid[index++] = timeString.charCodeAt(i);
-        }
-        
-        for (i = 0; i < 4; i++)
-        {
-            uid[index++] = ALPHA_CHAR_CODES[Math.floor(Math.random() *  16)];
-        }
-        
-        return String.fromCharCode.apply(null, uid);
-    }
+	public static function createUID():String
+	{
+		var uid:Array = EMPTYUID;
+		var index:int = 0;
+		
+		var i:int;
+		var j:int;
+		
+		for (i = 0; i < 8; i++)
+		{
+			uid[index++] = HEX_CHARS.charAt(Math.random() * 16);
+		}
+		
+		for (i = 0; i < 3; i++)
+		{
+			index++; // skip "-"
+			
+			for (j = 0; j < 4; j++)
+			{
+				uid[index++] = HEX_CHARS.charAt(Math.random() * 16);
+			}
+		}
+		
+		index++; // skip "-"
+		
+		var time:Number = new Date().getTime();
+		// Note: time is the number of milliseconds since 1970,
+		// which is currently more than one trillion.
+		// We use the low 8 hex digits of this number in the UID.
+		// Just in case the system clock has been reset to
+		// Jan 1-4, 1970 (in which case this number could have only
+		// 1-7 hex digits), we pad on the left with 7 zeros
+		// before taking the low digits.
+		var timeString:String = ("0000000" + time.toString(16).toUpperCase()).substr(-8);
+		
+		for (i = 0; i < 8; i++)
+		{
+			uid[index++] = timeString.charAt(i);
+		}
+		
+		for (i = 0; i < 4; i++)
+		{
+			uid[index++] = HEX_CHARS.charAt(Math.random() * 16);
+		}
+		
+		return uid.join("");
+	}
 
     /**
      * Converts a 128-bit UID encoded as a ByteArray to a String representation.


Mime
View raw message