--- a/SequenceableCollection.st Wed Jul 09 16:59:43 2014 +0200
+++ b/SequenceableCollection.st Wed Jul 09 17:03:59 2014 +0200
@@ -82,13 +82,13 @@
sz "{ Class: SmallInteger }"|
sz := anArray size.
- collection := self withSize:sz-1.
+ collection := self newWithSize:sz-1.
2 to:sz do:[:idx| collection at:idx-1 put:(anArray at:idx) decodeAsLiteralArray].
^ collection
"
Array
- decodeFromLiteralArray:#(Array 1 2 3)
+ decodeFromLiteralArray:#(Array 1 2 3)
"
!
@@ -185,6 +185,22 @@
"
!
+newWithSize:size
+ "return a new collection of size.
+ For variable size collections, this is different from #new:,
+ in that #new: creates an empty collection with preallocated size,
+ while #withSize: creates a non empty one."
+
+ ^ (self new:size) grow:size.
+
+ "
+ (OrderedCollection new:10) inspect.
+ (OrderedCollection withSize:10) inspect.
+ (Array new:10) inspect.
+ (Array withSize:10) inspect.
+ "
+!
+
withSize:size
"return a new collection of size.
For variable size collections, this is different from #new:,
@@ -227,34 +243,34 @@
"this is a synthetic selector, generated by the compiler,
if a construct of the form expr[idx...] is parsed.
I.e.
- Array[n,m]
+ Array[n,m]
generates
- Array _at:n at:m
+ Array _at:n at:m
"
|data|
- data := self withSize:(dim1 * dim2).
+ data := self newWithSize:(dim1 * dim2).
^ MultiDimensionalArrayAccessor
- collection:data
- dimensions:(Array with:dim1 with:dim2)
+ collection:data
+ dimensions:(Array with:dim1 with:dim2)
!
_at:dim1 at:dim2 at:dim3
"this is a synthetic selector, generated by the compiler,
if a construct of the form expr[idx...] is parsed.
I.e.
- Array[n,m,o]
+ Array[n,m,o]
generates
- Array _at:n at:m at:o
+ Array _at:n at:m at:o
"
|data|
- data := self withSize:(dim1 * dim2 * dim3).
+ data := self newWithSize:(dim1 * dim2 * dim3).
^ MultiDimensionalArrayAccessor
- collection:data
- dimensions:(Array with:dim1 with:dim2 with:dim3)
+ collection:data
+ dimensions:(Array with:dim1 with:dim2 with:dim3)
! !
!SequenceableCollection class methodsFor:'instance creation-streaming'!
@@ -2553,7 +2569,7 @@
|newColl sz|
sz := self size.
- newColl := StringCollection withSize:sz.
+ newColl := StringCollection newWithSize:sz.
newColl replaceFrom:1 to:sz with:self startingAt:1.
^ newColl
@@ -3122,7 +3138,7 @@
]
].
totalLength := totalLength + ((endIndex - startIndex) * sepCnt).
- newColl := species withSize:totalLength.
+ newColl := species newWithSize:totalLength.
pos := 1.
startIndex to:endIndex do:[:index |
@@ -3554,7 +3570,7 @@
'abc' ,* 0
'abc' ,* 1
'a' ,* 50
- (1 to:4) ,* 20
+ (1 to:4) ,* 5
"
!
@@ -4550,7 +4566,7 @@
|newColl idx|
- newColl := self species new:(self size * nTimes).
+ newColl := self species newWithSize:(self size * nTimes).
idx := 1.
nTimes timesRepeat:[
newColl replaceFrom:idx with:self startingAt:1.
@@ -9789,11 +9805,11 @@
!SequenceableCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.388 2014-07-09 14:52:32 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.389 2014-07-09 15:03:59 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.388 2014-07-09 14:52:32 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.389 2014-07-09 15:03:59 cg Exp $'
! !