Levente Uzonyi uploaded a new version of EToys to project The Trunk:
http://source.squeak.org/trunk/EToys-ul.279.mcz
==================== Summary ====================
Name: EToys-ul.279
Author: ul
Time: 27 February 2017, 2:06:51.332279 am
UUID: 848b5ae7-df41-4c28-b99a-c19ff6ca7cb5
Ancestors: EToys-dtl.278
- omit ifAbsent from #index* sends when the default value 0 would used
=============== Diff against EToys-dtl.278 ===============
Item was changed:
----- Method: BookMorph>>pageNumberReport (in category '*Etoys-Squeakland-page controls') -----
pageNumberReport
"Answer a string representing the page number."
+ ^ (pages indexOf: currentPage) printString, '/', pages size printString!
- ^ (pages indexOf: currentPage ifAbsent: [0]) printString, '/', pages size printString!
Item was changed:
----- Method: CategoryViewer>>nextCategory (in category 'categories') -----
nextCategory
"Change the receiver to point at the category following the one currently seen"
| aList anIndex newIndex already aChoice |
aList := (scriptedPlayer categoriesForViewer: self) collect:
[:aCatSymbol | self currentVocabulary categoryWordingAt: aCatSymbol].
already := self outerViewer ifNil: [#()] ifNotNil: [self outerViewer categoriesCurrentlyShowing].
+ anIndex := aList indexOf: self currentCategory.
- anIndex := aList indexOf: self currentCategory ifAbsent: [0].
newIndex := anIndex = aList size
ifTrue: [1]
ifFalse: [anIndex + 1].
[already includes: (aChoice := aList at: newIndex)] whileTrue:
[newIndex := (newIndex \\ aList size) + 1].
self chooseCategoryWhoseTranslatedWordingIs: aChoice!
Item was changed:
----- Method: Debugger>>preDebugNotifierContentsFrom: (in category '*Etoys-Squeakland-initialize') -----
preDebugNotifierContentsFrom: messageString
| first second msg |
^ Preferences eToyFriendly
ifFalse:
[messageString]
ifTrue:
[
msg := messageString.
msg ifNil: [msg := ''].
first := second := 0.
+ first := msg indexOf: $\.
+ first > 0 ifTrue: [second := msg indexOf: $\ startingAt: first + 1].
- first := msg indexOf: $\ ifAbsent: [0].
- first > 0 ifTrue: [second := msg indexOf: $\ startingAt: first + 1 ifAbsent: [0]].
(first > 0 and: [second > 0]) ifTrue: [
'An error has occurred in\{3} of {2}.\Fix your script(s), hit ''Abandon'' and try again.' translated withCRs format: {msg copyFrom: 1 to: first - 1. msg copyFrom: first + 1 to: second - 1. msg copyFrom: second + 1 to: msg size}
] ifFalse: [
'An error has occurred; you should probably just hit ''abandon''. Sorry!!' translated
]
] !
Item was changed:
----- Method: KedamaSetColorComponentTile>>line1: (in category 'initialization') -----
line1: line1
| chopped label label2 tail headIndex |
(line1 select: [:e | e = $:]) size >= 2 ifTrue: [^ self].
self removeAllMorphs.
+ headIndex := line1 indexOf: $: ifAbsent: [line1 indexOf: Character space].
- headIndex := line1 indexOf: $: ifAbsent: [line1 indexOf: Character space ifAbsent: [0]].
chopped := line1 copyFrom: 1 to: headIndex - 1.
tail := line1 copyFrom: chopped size + 2 to: line1 size.
label := StringMorph contents: (chopped) translated font: ScriptingSystem fontForTiles.
label2 := StringMorph contents: tail translated font: ScriptingSystem fontForTiles.
self addMorphBack: label.
self addMorphBack: patchTile.
self addMorphBack: label2.
!
Item was changed:
----- Method: KedamaSetPixelValueTile>>line1: (in category 'tile protocol') -----
line1: line1
| chopped label label2 tail headIndex |
(line1 select: [:e | e = $:]) size >= 2 ifTrue: [^ self].
self removeAllMorphs.
+ headIndex := line1 indexOf: $: ifAbsent: [line1 indexOf: Character space].
- headIndex := line1 indexOf: $: ifAbsent: [line1 indexOf: Character space ifAbsent: [0]].
chopped := line1 copyFrom: 1 to: headIndex - 1.
tail := line1 copyFrom: chopped size + 2 to: line1 size.
label := StringMorph contents: (chopped) font: ScriptingSystem fontForTiles.
label2 := StringMorph contents: tail font: ScriptingSystem fontForTiles.
self addMorphBack: label.
self addMorphBack: patchTile.
self addMorphBack: label2.
!
Item was changed:
----- Method: Morph>>reassessBackgroundShape (in category '*Etoys-card in a stack') -----
reassessBackgroundShape
"A change has been made which may affect the instance structure of the Card uniclass that holds the instance state, which can also be thought of as the 'card data'."
"Caution: still to be done: the mechanism so that when a new instance variable is added, it gets initialized in all subinstances of the receiver's player, which are the cards of this shape. One needs to take into account here the instance variable names coming in; those that are unchanged should keep their values, but those that have newly arrived should obtain their default values from the morphs on whose behalf they are being maintained in the model"
| requestedName |
self isStackBackground ifFalse: [^Beeper beep]. "bulletproof against deconstruction"
Cursor wait showWhile:
[ | variableDocks takenNames sepDataMorphs sorted existing |variableDocks := OrderedCollection new. "This will be stored in the uniclass's
class-side inst var #variableDocks"
takenNames := OrderedCollection new.
sepDataMorphs := OrderedCollection new. "fields, holders of per-card data"
self submorphs do:
[:aMorph |
aMorph renderedMorph holdsSeparateDataForEachInstance
ifTrue: [sepDataMorphs add: aMorph renderedMorph]
ifFalse:
["look for buried fields, inside a frame"
aMorph renderedMorph isShared
ifTrue:
[aMorph allMorphs do:
[:mm |
mm renderedMorph holdsSeparateDataForEachInstance
ifTrue: [sepDataMorphs add: mm renderedMorph]]]]].
sorted := SortedCollection new
sortBlock: [:a :b | (a valueOfProperty: #cardInstance) notNil]. "puts existing ones first"
sorted addAll: sepDataMorphs.
sorted do:
[:aMorph | | docks |
docks := aMorph variableDocks.
"Each morph can request multiple variables.
This complicates matters somewhat but creates a generality for Fabrk-like uses.
Each spec is an instance of VariableDock, and it provides a point of departure
for the negotiation between the PasteUp and its constitutent morphs"
docks do:
[:aVariableDock | | uniqueName |
uniqueName := self player
uniqueInstanceVariableNameLike: (requestedName := aVariableDock
variableName)
excluding: takenNames.
uniqueName ~= requestedName
ifTrue:
[aVariableDock variableName: uniqueName.
aMorph noteNegotiatedName: uniqueName for: requestedName].
takenNames add: uniqueName].
variableDocks addAll: docks].
existing := self player class instVarNames.
variableDocks := (variableDocks asSortedCollection:
[:dock1 :dock2 | | name2 name1 |
name1 := dock1 variableName.
name2 := dock2 variableName.
+ (existing indexOf: name1)
- (existing indexOf: name1 ifAbsent: [0])
< (existing indexOf: name2 ifAbsent: [variableDocks size])])
asOrderedCollection.
self player class setNewInstVarNames: (variableDocks
collect: [:info | info variableName asString]).
"NB: sets up accessors, and removes obsolete ones"
self player class newVariableDocks: variableDocks]!
Item was changed:
----- Method: QuickGuideMorph>>jPegOutDir: (in category 'write web pages') -----
jPegOutDir: fileDir
"Write the current page of the current Guide as an image file on the directory"
"Does it need to be showing?"
| fName gn num qgh bk |
qgh := self submorphOfClass: QuickGuideHolderMorph.
bk := qgh submorphOfClass: BookMorph.
+ num := (bk pages indexOf: bk currentPage) printString.
- num := (bk pages indexOf: bk currentPage ifAbsent: [0]) printString.
gn := qgh guideName.
fName := fileDir pathName, fileDir pathNameDelimiter asString, gn, '-', num, '.jpg'.
currentPage imageForm writeJPEGfileNamed: fName.
"need to go deeper??"
^ ''!
Item was changed:
----- Method: StackMorph>>cardNumberOf: (in category 'accessing') -----
cardNumberOf: aPlayer
"Answer the card-number of the given player, in the which-card-of-the-stack sense."
+ ^ self cards identityIndexOf: aPlayer!
- ^ self cards identityIndexOf: aPlayer ifAbsent: [0]!
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.738.mcz
==================== Summary ====================
Name: Collections-ul.738
Author: ul
Time: 27 February 2017, 12:50:24.923499 am
UUID: 3cdaac93-5a62-4fb6-8037-4323767c63a1
Ancestors: Collections-ul.737
Part #3 of Improve SequenceableCollection's index-related search methods
- fixed typo in #indexOf:startingAt:ifAbsent:
- trimmed unnecessary #ifAbsent: sends
- improved a few methods
=============== Diff against Collections-ul.737 ===============
Item was changed:
----- Method: ByteString>>substrings (in category 'converting') -----
substrings
"Answer an array of the substrings that compose the receiver."
+
+ ^Array streamContents: [ :stream |
+ | end start |
+ end := 1.
+ "find one substring each time through this loop"
+ [ "find the beginning of the next substring"
+ (start := self
+ indexOfAnyOf: CharacterSet nonSeparators
+ startingAt: end) = 0 ]
+ whileFalse: [
+ "find the end"
+ end := self
+ indexOfAnyOf: CharacterSet separators
+ startingAt: start
+ ifAbsent: [ self size + 1 ].
+ stream nextPut: (self copyFrom: start to: end - 1) ] ]!
- | result end beginning |
- result := WriteStream on: (Array new: 10).
- end := 0.
- "find one substring each time through this loop"
- [ "find the beginning of the next substring"
- beginning := self indexOfAnyOf: CharacterSet nonSeparators
- startingAt: end+1 ifAbsent: [ nil ].
- beginning ~~ nil ] whileTrue: [
- "find the end"
- end := self indexOfAnyOf: CharacterSet separators
- startingAt: beginning ifAbsent: [ self size + 1 ].
- end := end - 1.
- result nextPut: (self copyFrom: beginning to: end).
- ].
- ^result contents!
Item was changed:
----- Method: RWBinaryOrTextStream>>upTo: (in category 'accessing') -----
upTo: anObject
"fast version using indexOf:"
| start end |
- start := position+1.
isBinary
ifTrue: [ anObject isInteger ifFalse: [ ^self upToEnd ] ]
ifFalse: [ anObject isCharacter ifFalse: [ ^self upToEnd ] ].
+ start := position + 1.
+ end := collection indexOf: anObject asCharacter startingAt: start.
- end := collection indexOf: anObject asCharacter startingAt: start ifAbsent: [ 0 ].
"not present--return rest of the collection"
(end = 0 or: [end > readLimit]) ifTrue: [ ^self upToEnd ].
"skip to the end and return the data passed over"
position := end.
^((isBinary ifTrue: [ ByteArray ] ifFalse: [ String ]) new: end - start)
replaceFrom: 1
to: end - start
with: collection
startingAt: start!
Item was changed:
----- Method: ReadStream>>upToAnyOf:do: (in category 'accessing') -----
upToAnyOf: aCollection do: aBlock
"Overriden for speed"
| end result |
+ end := collection indexOfAnyOf: aCollection startingAt: 1 + position.
- end := collection indexOfAnyOf: aCollection startingAt: 1 + position ifAbsent: [0].
(end = 0 or: [end > readLimit]) ifTrue: [^self upToEnd].
result := collection copyFrom: 1 + position to: -1 + end.
position := end.
aBlock value: (collection at: end).
^result!
Item was changed:
----- Method: SequenceableCollection>>indexOf:startingAt:ifAbsent: (in category 'accessing') -----
indexOf: anElement startingAt: start ifAbsent: exceptionBlock
"Answer the index of the first occurence of anElement after start
within the receiver. If the receiver does not contain anElement,
answer the result of evaluating the argument, exceptionBlock."
| index |
+ (index := self indexOf: anElement startingAt: start) = 0 ifFalse: [ ^index ].
- (index := self indexOf: start startingAt: start) = 0 ifFalse: [ ^index ].
^exceptionBlock value!
Item was changed:
----- Method: String>>withBlanksTrimmed (in category 'converting') -----
withBlanksTrimmed
"Return a copy of the receiver from which leading and trailing blanks have been trimmed."
| first last |
+ first := self indexOfAnyOf: CharacterSet nonSeparators startingAt: 1.
- first := self indexOfAnyOf: CharacterSet nonSeparators startingAt: 1 ifAbsent: [0].
first = 0 ifTrue: [ ^'' ]. "no non-separator character"
last := self lastIndexOfAnyOf: CharacterSet nonSeparators startingAt: self size ifAbsent: [self size].
(first = 1 and: [ last = self size ]) ifTrue: [ ^self copy ].
^self
copyFrom: first
to: last
!
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.736.mcz
==================== Summary ====================
Name: Collections-ul.736
Author: ul
Time: 26 February 2017, 9:40:39.679834 pm
UUID: 81b6c60e-5ac9-4fd9-a53e-ba9259958a1d
Ancestors: Collections-ul.735
Part #1 of Improve SequenceableCollection's index-related search methods
- moved actual implementations (in subclasses too) to block-free methods: #indexOf:startingAt:, #identityIndexOf:startingAt:, #indexOfAnyOf:startingAt:, #indexOfSubCollection:startingAt:, #lastIndexOf:startingAt: and #lastIndexOfAnyOf:startingAt:
- added #identityIndexOf:startingAt:, #identityIndexOf:startingAt:ifAbsent:, #lastIndexOfAnyOf:, #lastIndexOfAnyOf:ifAbsent:
- removed the now unnecessary #indexOf: override from ByteArray ans String
- pulled up #indexOfSubCollection: from String
- improved #replaceAll:with:
=============== Diff against Collections-ul.735 ===============
Item was removed:
- ----- Method: ByteArray>>indexOf: (in category 'accessing') -----
- indexOf: anInteger
-
- ^self indexOf: anInteger startingAt: 1!
Item was added:
+ ----- Method: Interval>>indexOf:startingAt: (in category 'accessing') -----
+ indexOf: anElement startingAt: startIndex
+ "startIndex is an positive integer, the collection index where the search is started."
+ "during the computation of val , floats are only used when the receiver contains floats"
+
+ | index val |
+ (self rangeIncludes: anElement) ifFalse: [ ^0 ].
+ val := anElement - self first / self increment.
+ val isFloat
+ ifTrue: [
+ (val - val rounded) abs * 100000000 < 1 ifFalse: [ ^0 ].
+ index := val rounded + 1 ]
+ ifFalse: [
+ val isInteger ifFalse: [ ^0 ].
+ index := val + 1 ].
+ "finally, the value of startIndex comes into play:"
+ (index between: startIndex and: self size) ifFalse: [ ^0 ].
+ ^index!
Item was added:
+ ----- Method: LinkedList>>indexOf:startingAt: (in category 'private') -----
+ indexOf: anElement startingAt: start
+ "Answer the index of the first occurence of anElement after start
+ within the receiver. If the receiver does not contain anElement,
+ answer the result of evaluating the argument, exceptionBlock."
+
+ |currentLink index|
+ currentLink := self linkAt: start ifAbsent: [nil].
+ index := start.
+ [ currentLink == nil ]
+ whileFalse: [currentLink value = anElement value ifTrue: [^index].
+ currentLink := currentLink nextLink.
+ index := index +1].
+ ^0!
Item was added:
+ ----- Method: OrderedCollection>>indexOf:startingAt: (in category 'accessing') -----
+ indexOf: anElement startingAt: start
+ "Optimized version."
+
+ firstIndex + start - 1 to: lastIndex do: [ :index |
+ (array at: index) = anElement ifTrue: [ ^index - firstIndex + 1 ] ].
+ ^0!
Item was changed:
----- Method: SequenceableCollection>>identityIndexOf: (in category 'accessing') -----
identityIndexOf: anElement
"Answer the index of anElement within the receiver. If the receiver does
not contain anElement, answer 0."
+ ^self identityIndexOf: anElement startingAt: 1!
- ^self identityIndexOf: anElement ifAbsent: [0]!
Item was changed:
----- Method: SequenceableCollection>>identityIndexOf:ifAbsent: (in category 'accessing') -----
identityIndexOf: anElement ifAbsent: exceptionBlock
"Answer the index of anElement within the receiver. If the receiver does
not contain anElement, answer the result of evaluating the argument,
exceptionBlock."
+
+ | index |
+ (index := self identityIndexOf: anElement startingAt: 1) = 0 ifFalse: [ ^index ].
+ ^exceptionBlock value!
- 1 to: self size do:
- [:i | (self at: i) == anElement ifTrue: [^ i]].
- ^ exceptionBlock value!
Item was added:
+ ----- Method: SequenceableCollection>>identityIndexOf:startingAt: (in category 'accessing') -----
+ identityIndexOf: anElement startingAt: startIndex
+ "Answer the index of anElement within the receiver starting at startIndex.
+ If the receiver does not contain anElement, answer 0."
+
+ startIndex to: self size do: [ :index |
+ (self at: index) == anElement ifTrue: [ ^index ] ].
+ ^0!
Item was added:
+ ----- Method: SequenceableCollection>>identityIndexOf:startingAt:ifAbsent: (in category 'accessing') -----
+ identityIndexOf: anElement startingAt: startIndex ifAbsent: exceptionBlock
+ "Answer the index of anElement within the receiver starting at startIndex.
+ If the receiver does not contain anElement, answer the result of evaluating
+ the argument, exceptionBlock."
+
+ | index |
+ (index := self identityIndexOf: anElement startingAt: 1) = 0 ifFalse: [ ^index ].
+ ^exceptionBlock value!
Item was changed:
----- Method: SequenceableCollection>>indexOf: (in category 'accessing') -----
indexOf: anElement
"Answer the index of the first occurence of anElement within the
receiver. If the receiver does not contain anElement, answer 0."
+ ^self indexOf: anElement startingAt: 1!
- ^ self indexOf: anElement ifAbsent: [0]!
Item was changed:
----- Method: SequenceableCollection>>indexOf:ifAbsent: (in category 'accessing') -----
indexOf: anElement ifAbsent: exceptionBlock
"Answer the index of the first occurence of anElement within the
receiver. If the receiver does not contain anElement, answer the
result of evaluating the argument, exceptionBlock."
+ | index |
+ (index := self indexOf: anElement startingAt: 1) = 0 ifFalse: [ ^index ].
+ ^exceptionBlock value!
- ^ self indexOf: anElement startingAt: 1 ifAbsent: exceptionBlock!
Item was changed:
----- Method: SequenceableCollection>>indexOf:startingAt: (in category 'accessing') -----
indexOf: anElement startingAt: start
"Answer the index of the first occurence of anElement after start
within the receiver. If the receiver does not contain anElement,
answer 0."
+ start to: self size do: [ :index |
+ (self at: index) = anElement ifTrue: [ ^index ] ].
+ ^0!
- ^self indexOf: anElement startingAt: start ifAbsent: 0!
Item was changed:
----- Method: SequenceableCollection>>indexOfAnyOf: (in category 'accessing') -----
indexOfAnyOf: aCollection
"Answer the index of the first occurence of any element included in aCollection within the receiver.
If the receiver does not contain anElement, answer zero, which is an invalid index."
+ ^self indexOfAnyOf: aCollection startingAt: 1!
- ^self indexOfAnyOf: aCollection startingAt: 1 ifAbsent: [0]!
Item was changed:
----- Method: SequenceableCollection>>indexOfAnyOf:startingAt: (in category 'accessing') -----
indexOfAnyOf: aCollection startingAt: start
"Answer the index of the first occurence of any element included in aCollection after start within the receiver.
If the receiver does not contain anElement, answer zero, which is an invalid index."
+ start to: self size do: [ :index |
+ (aCollection includes: (self at: index)) ifTrue: [ ^index ] ].
+ ^0!
- ^self indexOfAnyOf: aCollection startingAt: start ifAbsent: [0]!
Item was added:
+ ----- Method: SequenceableCollection>>indexOfSubCollection: (in category 'accessing') -----
+ indexOfSubCollection: aSubCollection
+ "Answer the index of the receiver's first element, such that that element
+ equals the first element of aSubCollection, and the next elements equal
+ the rest of the elements of aSubCollection. Begin the search at the first
+ element of the receiver. If no such match is found, answer 0."
+
+ ^self
+ indexOfSubCollection: aSubCollection
+ startingAt: 1!
Item was changed:
----- Method: SequenceableCollection>>indexOfSubCollection:startingAt: (in category 'accessing') -----
+ indexOfSubCollection: subCollection startingAt: start
- indexOfSubCollection: aSubCollection startingAt: anIndex
"Answer the index of the receiver's first element, such that that element
+ equals the first element of sub, and the next elements equal
+ the rest of the elements of sub. Begin the search at element
+ start of the receiver. If no such match is found, answer 0."
- equals the first element of aSubCollection, and the next elements equal
- the rest of the elements of aSubCollection. Begin the search at element
- anIndex of the receiver. If no such match is found, answer 0."
+ | first index subCollectionSize |
+ (subCollectionSize := subCollection size) = 0 ifTrue: [ ^0 ].
+ first := subCollection at: 1.
+ (start max: 1) to: self size - subCollectionSize + 1 do: [ :startIndex |
+ (self at: startIndex) = first ifTrue: [
+ index := 2.
+ [ index <= subCollectionSize
+ and: [ (self at: startIndex + index - 1) = (subCollection at: index) ] ]
+ whileTrue: [ index := index + 1 ].
+ index <= subCollectionSize ifFalse: [ ^startIndex ] ] ].
+ ^0!
- ^self
- indexOfSubCollection: aSubCollection
- startingAt: anIndex
- ifAbsent: [0]!
Item was changed:
----- Method: SequenceableCollection>>lastIndexOf: (in category 'accessing') -----
lastIndexOf: anElement
"Answer the index of the last occurence of anElement within the
receiver. If the receiver does not contain anElement, answer 0."
+ ^self lastIndexOf: anElement startingAt: self size!
- ^ self lastIndexOf: anElement startingAt: self size ifAbsent: [0]!
Item was changed:
----- Method: SequenceableCollection>>lastIndexOf:ifAbsent: (in category 'accessing') -----
lastIndexOf: anElement ifAbsent: exceptionBlock
"Answer the index of the last occurence of anElement within the
receiver. If the receiver does not contain anElement, answer the
result of evaluating the argument, exceptionBlock."
+
+ | index |
+ (index := self lastIndexOf: anElement startingAt: self size) = 0 ifFalse: [ ^index ].
+ ^exceptionBlock value!
- ^self lastIndexOf: anElement startingAt: self size ifAbsent: exceptionBlock!
Item was added:
+ ----- Method: SequenceableCollection>>lastIndexOf:startingAt: (in category 'accessing') -----
+ lastIndexOf: anElement startingAt: lastIndex
+ "Answer the index of the last occurence of anElement within the
+ receiver. If the receiver does not contain anElement, answer the
+ result of evaluating the argument, exceptionBlock."
+
+ lastIndex to: 1 by: -1 do: [ :index |
+ (self at: index) = anElement ifTrue: [ ^index ] ].
+ ^0!
Item was changed:
----- Method: SequenceableCollection>>lastIndexOf:startingAt:ifAbsent: (in category 'accessing') -----
lastIndexOf: anElement startingAt: lastIndex ifAbsent: exceptionBlock
"Answer the index of the last occurence of anElement within the
receiver. If the receiver does not contain anElement, answer the
result of evaluating the argument, exceptionBlock."
+ | index |
+ (index := self lastIndexOf: anElement startingAt: lastIndex) = 0 ifFalse: [ ^index ].
+ ^exceptionBlock value!
- lastIndex to: 1 by: -1 do:
- [:index |
- (self at: index) = anElement ifTrue: [^ index]].
- ^ exceptionBlock value!
Item was added:
+ ----- Method: SequenceableCollection>>lastIndexOfAnyOf: (in category 'accessing') -----
+ lastIndexOfAnyOf: aCollection
+ "Answer the index of the last occurence of any element of aCollection
+ within the receiver. If the receiver does not contain any of those
+ elements, answer 0"
+
+ ^self lastIndexOfAnyOf: aCollection startingAt: self size!
Item was added:
+ ----- Method: SequenceableCollection>>lastIndexOfAnyOf:ifAbsent: (in category 'accessing') -----
+ lastIndexOfAnyOf: aCollection ifAbsent: exceptionBlock
+ "Answer the index of the last occurence of any element of aCollection
+ within the receiver. If the receiver does not contain any of those
+ elements, answer the result of evaluating the argument, exceptionBlock."
+
+ | index |
+ (index := self lastIndexOfAnyOf: aCollection startingAt: self size) = 0 ifFalse: [ ^index ].
+ ^exceptionBlock value!
Item was added:
+ ----- Method: SequenceableCollection>>lastIndexOfAnyOf:startingAt: (in category 'accessing') -----
+ lastIndexOfAnyOf: aCollection startingAt: lastIndex
+ "Answer the index of the last occurence of any element of aCollection
+ within the receiver. If the receiver does not contain any of those
+ elements, answer 0"
+
+ lastIndex to: 1 by: -1 do: [ :index |
+ (aCollection includes: (self at: index)) ifTrue: [ ^index ] ].
+ ^0!
Item was changed:
----- Method: SequenceableCollection>>lastIndexOfAnyOf:startingAt:ifAbsent: (in category 'accessing') -----
lastIndexOfAnyOf: aCollection startingAt: lastIndex ifAbsent: exceptionBlock
+ "Answer the index of the last occurence of any element of aCollection
+ within the receiver. If the receiver does not contain any of those
+ elements, answer the result of evaluating the argument, exceptionBlock."
- "Answer the index of the last occurence of anElement within the
- receiver. If the receiver does not contain anElement, answer the
- result of evaluating the argument, exceptionBlock."
+ | index |
+ (index := self lastIndexOfAnyOf: aCollection startingAt: lastIndex) = 0 ifFalse: [ ^index ].
+ ^exceptionBlock value!
- lastIndex to: 1 by: -1 do:
- [:index |
- (aCollection includes: (self at: index)) ifTrue: [^ index]].
- ^ exceptionBlock value!
Item was changed:
----- Method: SequenceableCollection>>replaceAll:with: (in category 'accessing') -----
replaceAll: oldObject with: newObject
"Replace all occurences of oldObject with newObject"
+
| index |
+ index := 0.
+ [ (index := self indexOf: oldObject startingAt: index + 1) = 0 ]
+ whileFalse: [ self at: index put: newObject ]!
- index := self
- indexOf: oldObject
- startingAt: 1
- ifAbsent: [0].
- [index = 0]
- whileFalse:
- [self at: index put: newObject.
- index := self
- indexOf: oldObject
- startingAt: index + 1
- ifAbsent: [0]]!
Item was removed:
- ----- Method: String>>indexOf: (in category 'accessing') -----
- indexOf: aCharacter
-
- ^self indexOf: aCharacter startingAt: 1
- !
Item was removed:
- ----- Method: String>>indexOfSubCollection: (in category 'accessing') -----
- indexOfSubCollection: sub
- #Collectn.
- "Added 2000/04/08 For ANSI <sequenceReadableCollection> protocol."
- ^ self
- indexOfSubCollection: sub
- startingAt: 1
- ifAbsent: [0]!
Eliot Miranda uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-eem.734.mcz
==================== Summary ====================
Name: Collections-eem.734
Author: eem
Time: 24 February 2017, 3:51:29.783168 pm
UUID: a81dce52-1da2-4c87-b8a7-fd6bf485396b
Ancestors: Collections-topa.733
Eliminate the ugly hack to speed up stream wide character writes. The trade-offs with Spur have changed and the cure is now arguably worse than the disease. The VM no longer supports the primitive (since it cannot be sufficiently polymorphic). hence the hack is paid for on every write but pays off only on wide chaacter writes to byte strings. Now that Spur's become is much faster than V3 let's accept that the writing of a wide character to a byte string stream won't be as fast, since all other stream writes will be.
Slightly faster (and correctly commented) version of isSeparator.
=============== Diff against Collections-topa.733 ===============
Item was changed:
----- Method: Character>>isSeparator (in category 'testing') -----
isSeparator
"Answer whether the receiver is one of the separator characters--space,
cr, tab, line feed, or form feed."
| integerValue |
+ (integerValue := self asInteger) > 32 ifTrue: [^false].
+ ^#(false false false false false false false false false
+ true "9 = tab"
+ true "10 = line feed"
+ false
+ true "12 = form feed"
+ true "13 = cr"
+ false false false false false false false false false false false false false false false false false false
+ true) at: integerValue + 1!
- (integerValue := self asInteger) > 32 ifTrue: [ ^false ].
- integerValue
- caseOf: {
- [ 32 "space" ] -> [ ^true ].
- [ 9 "cr" ] -> [ ^true ].
- [ 13 "tab"] -> [ ^true ].
- [ 10 "line feed" ] -> [ ^true ] }
- otherwise: [ ^integerValue = 12 "form feed" ]!
Item was changed:
----- Method: WriteStream>>nextPut: (in category 'accessing') -----
nextPut: anObject
"Primitive. Insert the argument at the next position in the Stream
represented by the receiver. Fail if the collection of this stream is not an
Array or a String. Fail if the stream is positioned at its end, or if the
position is out of bounds in the collection. Fail if the argument is not
of the right type for the collection. Optional. See Object documentation
whatIsAPrimitive."
<primitive: 66>
- ((collection class == ByteString) and: [
- anObject isCharacter and:[anObject isOctetCharacter not]]) ifTrue: [
- collection := (WideString from: collection).
- ^self nextPut: anObject.
- ].
position >= writeLimit
ifTrue: [^ self pastEndPut: anObject]
ifFalse:
[position := position + 1.
^collection at: position put: anObject]!