Speed up #decodeFromLiteralArray:
authorStefan Vogel <sv@exept.de>
Sat, 09 Apr 2005 00:55:22 +0200
changeset 8831 918f291920c2
parent 8830 df7adfaf1a57
child 8832 8210e23f6c32
Speed up #decodeFromLiteralArray:
Dictionary.st
SequenceableCollection.st
Set.st
--- a/Dictionary.st	Sat Apr 09 00:49:31 2005 +0200
+++ b/Dictionary.st	Sat Apr 09 00:55:22 2005 +0200
@@ -158,15 +158,17 @@
 decodeFromLiteralArray:anArray
     "create & return a new instance from information encoded in anArray."
 
-    |col|
+    |dictionary 
+     sz "{ Class: SmallInteger }"|
 
-    col := self new.
-    2 to:anArray size by:2 do:[:idx | |key val|
+    sz := anArray size.
+    dictionary := self new:sz//2.
+    2 to:sz by:2 do:[:idx | |key val|
         key := (anArray at:idx) decodeAsLiteralArray.
         val := (anArray at:idx+1) decodeAsLiteralArray.
-        col at:key put:val 
+        dictionary at:key put:val 
     ].
-    ^ col
+    ^ dictionary
 
     "
      (Dictionary new
@@ -250,7 +252,6 @@
     "
 ! !
 
-
 !Dictionary methodsFor:'accessing'!
 
 associationAt:aKey
@@ -1922,7 +1923,7 @@
 !Dictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.83 2004-07-06 13:08:35 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.84 2005-04-08 22:54:22 stefan Exp $'
 ! !
 
 Dictionary initialize!
--- a/SequenceableCollection.st	Sat Apr 09 00:49:31 2005 +0200
+++ b/SequenceableCollection.st	Sat Apr 09 00:55:22 2005 +0200
@@ -79,13 +79,15 @@
 
 decodeFromLiteralArray:anArray
     "create & return a new instance from information encoded in anArray.
-     Redefined for faster creation.
-    "
-    |col i|
-    col := self withSize:anArray size - 1.
-    i := 1.
-    anArray from:2 do:[:el| col at:i put:el decodeAsLiteralArray. i := i + 1].
-    ^ col
+     Redefined for faster creation."
+
+    |collection 
+     sz "{ Class: SmallInteger }"|
+
+    sz := anArray size.
+    collection := self withSize:sz-1.
+    2 to:sz do:[:idx| collection at:idx-1 put:(anArray at:idx) decodeAsLiteralArray].
+    ^ collection
 
     "
      Array
@@ -6669,7 +6671,7 @@
 !SequenceableCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.220 2005-03-23 18:43:21 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.221 2005-04-08 22:55:22 stefan Exp $'
 ! !
 
 SequenceableCollection initialize!
--- a/Set.st	Sat Apr 09 00:49:31 2005 +0200
+++ b/Set.st	Sat Apr 09 00:55:22 2005 +0200
@@ -114,16 +114,18 @@
 decodeFromLiteralArray:anArray
     "create & return a new instance from information encoded in anArray."
 
-    |col|
+    |set 
+     sz "{ Class: SmallInteger }"|
 
-    col := self new:anArray size - 1.
-    anArray from:2 do:[:el | col add:el decodeAsLiteralArray].
-    ^ col
+    sz := anArray size.
+    set := self new:sz-1.
+    2 to:sz do:[:idx| set add:(anArray at:idx) decodeAsLiteralArray].
+    ^ set
 
     "
      (Set with:1234
-	  with:(1 @ 2)
-	  with:'hello'
+          with:(1 @ 2)
+          with:'hello'
      ) literalArrayEncoding decodeAsLiteralArray    
     "
 !
@@ -1167,7 +1169,7 @@
 !Set class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.91 2004-09-30 12:01:24 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.92 2005-04-08 22:54:37 stefan Exp $'
 ! !
 
 Set initialize!