[squeak-dev] The Inbox: Collections-ct.851.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Aug 15 21:36:26 UTC 2019
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.851.mcz
==================== Summary ====================
Name: Collections-ct.851
Author: ct
Time: 15 August 2019, 11:36:23.694735 pm
UUID: 6c7113c6-9d09-bf4c-9b32-e2001870bb56
Ancestors: Collections-ct.850
Refactor String>>#format: according to Text>>#format:
I could not find any significant performance impacts.
We have some duplication between both #format: implementations. Do you thing this is a problem at the current scale?
=============== Diff against Collections-ct.850 ===============
Item was changed:
----- Method: String>>format: (in category 'formatting') -----
+ format: arguments
+ "format the receiver with arguments
- format: aCollection
- "format the receiver with aCollection
simplest example:
'foo {1} bar' format: {Date today}.
complete example:
'\{ \} \\ foo {1} bar {2}' format: {12. 'string'}.
"
+ ^self class new: self size * 11 // 10 streamContents: [ :output |
- ^self class new: self size * 11 // 10 "+10%" streamContents: [ :output |
| lastIndex nextIndex |
lastIndex := 1.
[ (nextIndex := self indexOfAnyOf: FormatCharacterSet startingAt: lastIndex) = 0 ] whileFalse: [
nextIndex = lastIndex ifFalse: [
output next: nextIndex - lastIndex putAll: self startingAt: lastIndex ].
+ (self at: nextIndex) caseOf: {
+ [$\] -> [ output nextPut: (self at: (nextIndex := nextIndex + 1)) ].
+ [${] -> [
- (self at: nextIndex) == $\
- ifTrue: [ output nextPut: (self at: (nextIndex := nextIndex + 1)) ]
- ifFalse: [ "${"
"Parse the index - a positive integer in base 10."
+ | character collectionIndex |
- | digitValue collectionIndex |
collectionIndex := 0.
+ [ (character := self at: (nextIndex := nextIndex + 1)) isDigit ] whileTrue: [
+ collectionIndex := collectionIndex * 10 + character digitValue ].
+ character = $} ifFalse: [ self error: '$} expected' ].
+ output nextPutAll: (arguments at: collectionIndex) asString ] }.
- [ (digitValue := self basicAt: (nextIndex := nextIndex + 1)) between: 48 "$0 asciiValue" and: 57 "$9 asciiValue" ] whileTrue: [
- collectionIndex := collectionIndex * 10 + digitValue - 48. "$0 asciiValue" ].
- digitValue = 125 "$} asciiValue" ifFalse: [ self error: '$} expected' ].
- output nextPutAll: (aCollection at: collectionIndex) asString ].
lastIndex := nextIndex + 1 ].
lastIndex <= self size ifTrue: [
output next: self size - lastIndex + 1 putAll: self startingAt: lastIndex ] ]!
More information about the Squeak-dev
mailing list
|