The Trunk: Collections-ul.682.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-ul.682.mcz

commits-2
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.682.mcz

==================== Summary ====================

Name: Collections-ul.682
Author: ul
Time: 20 March 2016, 12:59:06.124515 am
UUID: 5276c8f7-606f-42d1-9ce5-e48b88fdac2d
Ancestors: Collections-ul.681

- avoid creating intermediate objects in String >> #padded:to:with:

=============== Diff against Collections-ul.681 ===============

Item was changed:
  ----- Method: String>>padded:to:with: (in category 'copying') -----
+ padded: leftOrRight to: length with: aCharacter
+
+ | result paddingLength |
+ (paddingLength := length - self size) <= 0 ifTrue: [ ^self ].
+ result := self species new: length.
+ leftOrRight = #left ifTrue: [
+ ^result
+ from: 1
+ to: paddingLength
+ put: aCharacter;
+ replaceFrom: paddingLength + 1
+ to: length
+ with: self
+ startingAt: 1;
+ yourself ].
+ leftOrRight = #right ifTrue: [
+ ^result
+ replaceFrom: 1
+ to: self size
+ with: self
+ startingAt: 1;
+ from: self size + 1
+ to: length
+ put: aCharacter;
+ yourself ]!
- padded: leftOrRight to: length with: char
- leftOrRight = #left ifTrue:
- [^ (String new: (length - self size max: 0) withAll: char) , self].
- leftOrRight = #right ifTrue:
- [^ self , (String new: (length - self size max: 0) withAll: char)].!