[squeak-dev] The Trunk: Collections-ct.867.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Apr 7 21:00:37 UTC 2022
Christoph Thiede uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ct.867.mcz
==================== Summary ====================
Name: Collections-ct.867
Author: ct
Time: 7 December 2019, 3:17:42.114431 pm
UUID: e757d3c9-f127-0c46-adcd-b5d5a5272b1f
Ancestors: Collections-mt.866
As requested, attempt to bring different #format: implementations closer together and optimize Text>>#format:.
Meanwhile, I learnt that integers may indeed be faster to compare than characters ( thanks Marcel :) ). If you notice any other slips, I will be happy to fix them.
=============== Diff against Collections-mt.866 ===============
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 "+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."
| digitValue collectionIndex |
collectionIndex := 0.
[ (digitValue := self basicAt: (nextIndex := nextIndex + 1)) between: 48 "$0 asciiValue" and: 57 "$9 asciiValue" ] whileTrue: [
+ collectionIndex := collectionIndex * 10 + digitValue - 48 "$0 asciiValue". ].
- collectionIndex := collectionIndex * 10 + digitValue - 48. "$0 asciiValue" ].
digitValue = 125 "$} asciiValue" ifFalse: [ self error: '$} expected' ].
+ output nextPutAll: (arguments at: collectionIndex) asString ] }.
- output nextPutAll: (aCollection at: collectionIndex) asString ].
lastIndex := nextIndex + 1 ].
lastIndex <= self size ifTrue: [
output next: self size - lastIndex + 1 putAll: self startingAt: lastIndex ] ]!
Item was changed:
----- Method: Text>>format: (in category 'formatting') -----
format: arguments
"format the receiver with arguments, respecting the format both of receiver and collection elements"
+ ^self class new: self size * 11 // 10 "+10%" streamContents: [ :output |
- ^self class new: self size * 11 // 10 streamContents: [ :output |
| nextIndex |
nextIndex := 1.
[ nextIndex <= self size ] whileTrue: [
(self at: nextIndex) caseOf: {
+ [ $\ ] -> [
- [$\] -> [
nextIndex := nextIndex + 1.
output withAttributes: (runs at: nextIndex) do: [
output nextPut: (self at: nextIndex) ] ].
+ [ ${ ] -> [
- [${] -> [
"Parse the index - a positive integer in base 10."
+ | digitValue collectionIndex attributes |
- | character collectionIndex attributes |
collectionIndex := 0.
attributes := Set new.
+ [ (digitValue := string basicAt: (nextIndex := nextIndex + 1)) between: 48 "$0 asciiValue" and: 57 "$9 asciiValue" ] whileTrue: [
+ collectionIndex := collectionIndex * 10 + digitValue - 48 "$0 asciiValue".
- [ (character := string at: (nextIndex := nextIndex + 1)) isDigit ] whileTrue: [
- collectionIndex := collectionIndex * 10 + character digitValue.
attributes addAll: (runs at: nextIndex) ].
+ digitValue = 125 "$} asciiValue" ifFalse: [ self error: '$} expected' ].
- character = $} ifFalse: [ self error: '$} expected' ].
output withAttributes: attributes do: [
output nextPutAll: (arguments at: collectionIndex) asStringOrText ] ] }
otherwise: [
output withAttributes: (runs at: nextIndex) do: [
output nextPut: (self at: nextIndex) ] ].
nextIndex := nextIndex + 1 ] ]!
More information about the Squeak-dev
mailing list
|