The Trunk: Collections-ul.872.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.872.mcz

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

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

Name: Collections-ul.872
Author: ul
Time: 4 February 2020, 1:26:07.104018 pm
UUID: 735423f6-6dbb-4f4a-b2a7-f311cc7e8806
Ancestors: Collections-nice.870

Various performance tweaks in a single commit:

- be straightforward in Dictionary >> #fillFrom:with:
        - when aCollection is a Dictionary use #associationsDo:, as it very likely it has associations, and it's faster than #keysAndValuesDo:
        - when it's not a Dictionary, use #do: instead of #associationsDo:, because the former is what we can expect a Collection to implement

- use existing search methods in String >> #findDelimiters:startingAt:, because those are faster, and there's no need to reinvent the wheel. All users other than #findTokens:* should be rewritten to use #indexOfAnyOf:* instead.

- almost twice as fast (amortized cost) Symbol >> #lookup: for existing symbols

(Same as Collections-ul.869 in the Treated Inbox but with updated Trunk ancestry.)

=============== Diff against Collections-nice.870 ===============

Item was changed:
  ----- Method: Dictionary>>fillFrom:with: (in category 'private') -----
  fillFrom: aCollection with: aBlock
  "Evaluate aBlock with each of aCollections's elements as the argument.  
  Collect the resulting values into self. Answer self."
 
  aCollection isDictionary
+ ifFalse: [
+ aCollection do: [ :element |
+ self add: (aBlock value: element) ] ]
+ ifTrue: [
+ aCollection associationsDo: [ :association |
+ self at: association key put: (aBlock value: association value) ] ]!
- ifFalse:
- [aCollection associationsDo:
- [ :element | self add: (aBlock value: element)]]
- ifTrue:
- [aCollection keysAndValuesDo:
- [ :key :value | self at: key put: (aBlock value: value)]]!

Item was changed:
  ----- Method: String>>findDelimiters:startingAt: (in category 'accessing') -----
  findDelimiters: delimiters startingAt: start
  "Answer the index of the character within the receiver, starting at start, that matches one of the delimiters. If the receiver does not contain any of the delimiters, answer size + 1."
 
+ delimiters size = 1 ifTrue: [ ^self indexOf: delimiters anyOne startingAt: start ifAbsent: self size + 1 ].
+ ^self indexOfAnyOf: delimiters startingAt: start ifAbsent: self size + 1!
- start to: self size do: [:i |
- delimiters do: [:delim | delim = (self at: i) ifTrue: [^ i]]].
- ^ self size + 1!

Item was changed:
  ----- Method: Symbol class>>lookup: (in category 'instance creation') -----
  lookup: aStringOrSymbol
 
  | originalNewSymbols originalSymbolTable |
  originalNewSymbols := NewSymbols.
  originalSymbolTable := SymbolTable.
+ ^(originalSymbolTable like: aStringOrSymbol) ifNil: [
+ originalNewSymbols like: aStringOrSymbol ]!
- ^(originalNewSymbols like: aStringOrSymbol) ifNil: [
- originalSymbolTable like: aStringOrSymbol ]!