[squeak-dev] The Trunk: Collections-ul.148.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Oct 1 04:00:26 UTC 2009


Andreas Raab uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.148.mcz

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

Name: Collections-ul.148
Author: ul
Time: 30 September 2009, 2:59:59 am
UUID: 7401c882-7922-a545-ac61-4a7d00fab136
Ancestors: Collections-ar.147

- replaced #whileFalse: with #whileFalse in #scanFor: and #scanForEmptySlotFor: implementations (both are inlined)
- don't share associatinos with the new Dictionary in Dictionary >> #select:
- avoid growing in Dictionary >> #collect:
- removed temporary from Set >> #like:

=============== Diff against Collections-ar.147 ===============

Item was changed:
  ----- Method: WeakSet>>scanFor: (in category 'private') -----
  scanFor: anObject
+ 	"Scan the key array for the first slot containing either flag (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
- 	"Scan the key array for the first slot containing either a nil or a flag (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  
  	| index start |
  	index := start := anObject hash \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == flag or: [ element = anObject ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: Set>>scanFor: (in category 'private') -----
  scanFor: anObject
  	"Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  
  	| index start |
  	index := start := anObject hash \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == nil or: [ element = anObject ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: IdentitySet>>scanForEmptySlotFor: (in category 'private') -----
  scanForEmptySlotFor: anObject
  	"Scan the key array for the first slot containing an empty slot (indicated by a nil). Answer the index of that slot. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start hash |
  	array size > 4096
  		ifTrue: [ hash := anObject identityHash * (array size // 4096) ]
  		ifFalse: [ hash := anObject identityHash ].
  	index := start := hash \\ array size + 1.
  	[ 
  		(array at: index) ifNil: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: Dictionary>>scanFor: (in category 'private') -----
  scanFor: anObject
  	"Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  
  	| index start |
  	index := start := anObject hash \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == nil or: [ element key = anObject ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: KeyedIdentitySet>>scanForEmptySlotFor: (in category 'private') -----
  scanForEmptySlotFor: anObject
  	"Scan the key array for the first slot containing an empty slot (indicated by a nil). Answer the index of that slot. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start hash |
  	array size > 4096
  		ifTrue: [ hash := anObject identityHash * (array size // 4096) ]
  		ifFalse: [ hash := anObject identityHash ].
  	index := start := hash \\ array size + 1.
  	[ 
  		(array at: index) ifNil: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: IdentityDictionary>>scanFor: (in category 'private') -----
  scanFor: anObject
  	"Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  
  	| index start hash |
  	array size > 4096
  		ifTrue: [ hash := anObject identityHash * (array size // 4096) ]
  		ifFalse: [ hash := anObject identityHash ].
  	index := start := hash \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == nil or: [ element key == anObject ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: WeakIdentityKeyDictionary>>scanFor: (in category 'private') -----
  scanFor: anObject
  	"Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  
  	| index start hash |
  	array size > 4096
  		ifTrue: [ hash := anObject identityHash * (array size // 4096) ]
  		ifFalse: [ hash := anObject identityHash ].
  	index := start := hash \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == nil or: [ element key == anObject ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: WeakSet>>scanForEmptySlotFor: (in category 'private') -----
  scanForEmptySlotFor: anObject
  	"Scan the key array for the first slot containing an empty slot (indicated by flag or a nil). Answer the index of that slot. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start |
  	index := start := anObject hash \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == flag or: [ element == nil ]) ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: IdentityDictionary>>scanForEmptySlotFor: (in category 'private') -----
  scanForEmptySlotFor: anObject
  	"Scan the key array for the first slot containing an empty slot (indicated by a nil). Answer the index of that slot. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start hash |
  	array size > 4096
  		ifTrue: [ hash := anObject identityHash * (array size // 4096) ]
  		ifFalse: [ hash := anObject identityHash ].
  	index := start := hash \\ array size + 1.
  	[ 
  		(array at: index) ifNil: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: Dictionary>>select: (in category 'enumerating') -----
  select: aBlock 
+ 	"Evaluate aBlock with each of my values as the argument. Collect into a new dictionary, only those associations for which aBlock evaluates to true."
- 	"Evaluate aBlock with each of my values as the argument. Collect into a
- 	new dictionary, only those associations for which aBlock evaluates to
- 	true."
  
  	| newCollection |
  	newCollection := self species new.
+ 	self associationsDo: [ :each |
+ 		(aBlock value: each value) ifTrue: [
+ 			newCollection add: each copy ] ].
- 	self associationsDo: 
- 		[:each | 
- 		(aBlock value: each value) ifTrue: [newCollection add: each]].
  	^newCollection!

Item was changed:
  ----- Method: Dictionary>>collect: (in category 'enumerating') -----
  collect: aBlock 
+ 	"Evaluate aBlock with each of my values as the argument.  Collect the resulting values into a collection that is like me. Answer with the new collection."
+ 	
- 	"Evaluate aBlock with each of my values as the argument.  Collect the
- 	resulting values into a collection that is like me. Answer with the new
- 	collection."
  	| newCollection |
+ 	newCollection := self species new: self size.
+ 	self associationsDo: [ :each |
+ 		newCollection at: each key put: (aBlock value: each value) ].
- 	newCollection := self species new.
- 	self associationsDo:[:each |
- 		newCollection at: each key put: (aBlock value: each value).
- 	].
  	^newCollection!

Item was changed:
  ----- Method: PluggableDictionary>>scanFor: (in category 'private') -----
  scanFor: anObject 
  	"Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start |
  	index := start := (hashBlock
  		ifNil: [ anObject hash ]
  		ifNotNil: [ hashBlock value: anObject ]) \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == nil or: [
  			equalBlock
  				ifNil: [ element key = anObject ]
  				ifNotNil: [ equalBlock value: element key value: anObject ] ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: Set>>scanForEmptySlotFor: (in category 'private') -----
  scanForEmptySlotFor: anObject
  	"Scan the key array for the first slot containing an empty slot (indicated by a nil). Answer the index of that slot. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start |
  	index := start := anObject hash \\ array size + 1.
  	[ 
  		(array at: index) ifNil: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: Set>>like: (in category 'accessing') -----
  like: anObject
  	"Answer an object in the receiver that is equal to anObject,
  	nil if no such object is found. Relies heavily on hash properties"
  
+ 	^array at: (self scanFor: anObject)!
- 	| index |
- 	index := self scanFor: anObject.
- 	^array at: index!

Item was changed:
  ----- Method: PluggableSet>>scanFor: (in category 'private') -----
  scanFor: anObject 
  	"Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start |
  	index := start := (hashBlock
  		ifNil: [ anObject hash ]
  		ifNotNil: [ hashBlock value: anObject ]) \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == nil or: [
  			equalBlock
  				ifNil: [ element = anObject ]
  				ifNotNil: [ equalBlock value: element value: anObject ] ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: WeakIdentityKeyDictionary>>scanForEmptySlotFor: (in category 'private') -----
  scanForEmptySlotFor: anObject
  	"Scan the key array for the first slot containing an empty slot (indicated by a nil). Answer the index of that slot. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start hash |
  	array size > 4096
  		ifTrue: [ hash := anObject identityHash * (array size // 4096) ]
  		ifFalse: [ hash := anObject identityHash ].
  	index := start := hash \\ array size + 1.
  	[ 
  		(array at: index) ifNil: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: PluggableDictionary>>scanForEmptySlotFor: (in category 'private') -----
  scanForEmptySlotFor: anObject
  	"Scan the key array for the first slot containing an empty slot (indicated by a nil). Answer the index of that slot. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start |
  	index := start := (hashBlock
  		ifNil: [ anObject hash ]
  		ifNotNil: [ hashBlock value: anObject ]) \\ array size + 1.
  	[ 
  		(array at: index) ifNil: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: IdentitySet>>scanFor: (in category 'private') -----
  scanFor: anObject
  	"Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  
  	| index start hash |
  	array size > 4096
  		ifTrue: [ hash := anObject identityHash * (array size // 4096) ]
  		ifFalse: [ hash := anObject identityHash ].
  	index := start := hash \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == nil or: [ element == anObject ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: KeyedIdentitySet>>scanFor: (in category 'private') -----
  scanFor: anObject
  	"Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  
  	| index start hash |
  	array size > 4096
  		ifTrue: [ hash := anObject identityHash * (array size // 4096) ]
  		ifFalse: [ hash := anObject identityHash ].
  	index := start := hash \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == nil or: [ (keyBlock value: element) == anObject ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: KeyedSet>>scanFor: (in category 'private') -----
  scanFor: anObject
  	"Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
  
  	| index start |
  	index := start := anObject hash \\ array size + 1.
  	[ 
  		| element |
  		((element := array at: index) == nil or: [ (keyBlock value: element) = anObject ])
  			ifTrue: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!

Item was changed:
  ----- Method: PluggableSet>>scanForEmptySlotFor: (in category 'private') -----
  scanForEmptySlotFor: anObject
  	"Scan the key array for the first slot containing an empty slot (indicated by a nil). Answer the index of that slot. This method will be overridden in various subclasses that have different interpretations for matching elements."
  	
  	| index start |
  	index := start := (hashBlock
  		ifNil: [ anObject hash ]
  		ifNotNil: [ hashBlock value: anObject ]) \\ array size + 1.
  	[ 
  		(array at: index) ifNil: [ ^index ].
+ 		(index := index \\ array size + 1) = start ] whileFalse.
- 		(index := index \\ array size + 1) = start ] whileFalse: [ ].
  	self errorNoFreeSpace!




More information about the Squeak-dev mailing list