#TUNING by cg
class: RunArray
tuning: use an OrderedCollection instead of Array for
the underlying runarray (to support fast add/addAll)
added: #addAll:
comment/format in: #setElementsFrom:
changed: #add:withOccurrences:
--- a/RunArray.st Thu Dec 06 14:08:18 2018 +0100
+++ b/RunArray.st Tue Dec 11 11:54:44 2018 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
This class is not covered by or part of the ST/X licence.
@@ -630,14 +632,13 @@
contentsArray at:lastIdx put:(contentsArray at:lastIdx) + n.
^ newObject
].
-
- newRuns := Array new:(runSz + 2).
- newRuns replaceFrom:1 to:runSz with:contentsArray.
- newRuns at:runSz+1 put:n.
- newRuns at:runSz+2 put:newObject.
+ (newRuns := contentsArray) isOrderedCollection ifFalse:[
+ newRuns := contentsArray asOrderedCollection.
+ ].
+ newRuns add:n; add:newObject.
contentsArray := newRuns.
] ifFalse:[
- contentsArray := Array with:n with:newObject.
+ contentsArray := OrderedCollection with:n with:newObject.
].
^ newObject
@@ -650,7 +651,24 @@
c add:2 withOccurrences:1000; yourself.
"
- "Modified: 11.5.1996 / 13:34:37 / cg"
+ "Modified: / 11-05-1996 / 13:34:37 / cg"
+ "Modified: / 11-12-2018 / 11:51:28 / Claus Gittinger"
+!
+
+addAll:aCollection
+ "add all elements of the argument, aCollection to the receiver.
+ Returns the argument, aCollection (sigh)."
+
+ aCollection class == RunArray ifTrue:[
+ contentsArray isOrderedCollection ifFalse:[
+ contentsArray := (contentsArray ? #()) asOrderedCollection.
+ ].
+ contentsArray addAll:(aCollection getContentsArray).
+ ^ aCollection
+ ].
+ ^ super addAll:aCollection.
+
+ "Created: / 11-12-2018 / 11:41:45 / Claus Gittinger"
! !
!RunArray methodsFor:'comparing'!
@@ -1094,11 +1112,6 @@
aCollection size == 0 ifTrue:[^ self].
- "/ to avoid the reallocations when using
- "/ multiple #add:withOccurrences: calls,
- "/ generate the runs collection as an orderedCollection
- "/ and convert to an array at the end.
-
nRuns := 0.
first := true.
aCollection do:[:element |
@@ -1147,6 +1160,7 @@
"Modified: / 07-04-1998 / 09:33:57 / cg"
"Modified (comment): / 25-01-2018 / 20:42:15 / mawalch"
+ "Modified (comment): / 11-12-2018 / 11:50:37 / Claus Gittinger"
!
setElementsFromRuns:runs values:values