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

commits at source.squeak.org commits at source.squeak.org
Tue Dec 1 05:13:32 UTC 2009


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

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

Name: Collections-ul.236
Author: ul
Time: 1 December 2009, 4:54:17 am
UUID: 7574c4aa-b907-1f4e-ba28-661aa9c084ae
Ancestors: Collections-ul.235

- revert #do: #associationsDo: and the senders of #scanForEmptySlotFor: 
- removed preamble
- add grow tweak to WeakSet
- rehash everything at postscript

=============== Diff against Collections-ul.235 ===============

Item was changed:
  ----- Method: KeyedSet>>noCheckNoGrowFillFrom: (in category 'private') -----
  noCheckNoGrowFillFrom: anArray
  	"Add the elements of anArray except nils to me assuming that I don't contain any of them, they are unique and I have more free space than they require."
  
  	1 to: anArray size do: [ :index |
  		| object |
  		(object := anArray at: index) ifNotNil: [
  			array
+ 				at: (self scanForEmptySlotFor: (keyBlock value: object))
- 				at: (self scanFor: (keyBlock value: object))
  				put: object ] ]!

Item was changed:
  ----- Method: WeakSet>>noCheckNoGrowFillFrom: (in category 'private') -----
  noCheckNoGrowFillFrom: anArray
  	"Add the elements of anArray except nils and flag to me assuming that I don't contain any of them, they are unique and I have more free space than they require."
  
  	tally := 0.
  	1 to: anArray size do: [ :index |
  		| object |
  		((object := anArray at: index) == flag or: [
  			object == nil ]) ifFalse: [ 
  				array
+ 					at: (self scanForEmptySlotFor: object)
- 					at: (self scanFor: object)
  					put: object.
  				tally := tally + 1 ] ]!

Item was changed:
  ----- Method: Set>>noCheckNoGrowFillFrom: (in category 'private') -----
  noCheckNoGrowFillFrom: anArray
  	"Add the elements of anArray except nils to me assuming that I don't contain any of them, they are unique and I have more free space than they require."
  
  	1 to: anArray size do: [ :index |
  		| object |
  		(object := anArray at: index) ifNotNil: [
  			array
+ 				at: (self scanForEmptySlotFor: object)
- 				at: (self scanFor: object)
  				put: object ] ]!

Item was added:
+ ----- Method: WeakSet>>grow (in category 'private') -----
+ grow
+ 	"Grow the elements array if needed.
+ 	Since WeakSets just nil their slots, a lot of the occupied (in the eyes of the set) slots are usually empty. Doubling size if unneeded can lead to BAD performance, therefore we see if reassigning the <live> elements to a Set of similiar size leads to a sufficiently (50% used here) empty set first"
+ 	
+ 	| oldTally |
+ 	oldTally := tally.
+ 	self rehash.
+ 	oldTally // 2 < tally ifTrue: [ super grow ]!

Item was changed:
  ----- Method: Dictionary>>noCheckNoGrowFillFrom: (in category 'private') -----
  noCheckNoGrowFillFrom: anArray
  	"Add the elements of anArray except nils to me assuming that I don't contain any of them, they are unique and I have more free space than they require."
  
  	1 to: anArray size do: [ :index |
  		| object |
  		(object := anArray at: index) ifNotNil: [
  			array
+ 				at: (self scanForEmptySlotFor: object key)
- 				at: (self scanFor: object key)
  				put: object ] ]!

Item was changed:
  ----- Method: WeakKeyDictionary>>noCheckNoGrowFillFrom: (in category 'private') -----
  noCheckNoGrowFillFrom: anArray
  	"Add the elements of anArray except nils and flag to me assuming that I don't contain any of them, they are unique and I have more free space than they require."
  
  	tally := 0.
  	1 to: anArray size do:[ :i |
  		| association |
  		(association := anArray at: i) ifNotNil: [
  			array
+ 				at: (self scanForEmptySlotFor: association key)
- 				at: (self scanFor: association key)
  				put: association.
  			tally := tally + 1 ] ]!

Item was changed:
  ----- Method: WeakSet>>do: (in category 'public') -----
  do: aBlock
  
+ 	tally = 0 ifTrue: [ ^self ].
+ 	1 to: array size do: [ :index |
+ 		| each |
+ 		((each := array at: index) == nil or: [ each == flag ])
- 	tally = 0 ifTrue: [^self].
- 	array do: [ :each |
- 		(each == nil or: [each == flag])
  			ifFalse: [ aBlock value: each ] ]!

Item was changed:
  ----- Method: WeakKeyDictionary>>finalizeValues: (in category 'finalization') -----
  finalizeValues: finiObjects
  	"Remove all associations with key == nil and value is in finiObjects.
  	This method is folded with #rehash for efficiency."
  	
  	| oldArray |
  	oldArray := array.
  	array := Array new: oldArray size.
  	tally := 0.
  	1 to: array size do:[ :i |
  		| association |
  		(association := oldArray at: i) ifNotNil: [
  			| key |
  			((key := association key) == nil and: [ "Don't let the key go away"
  				finiObjects includes: association value ])
  					ifFalse: [
  						array 
+ 							at: (self scanForEmptySlotFor: key) 
- 							at: (self scanFor: key) 
  							put: association.
  						tally := tally + 1 ] ] ]!

Item was changed:

Item was changed:
  ----- Method: WeakKeyToCollectionDictionary>>noCheckNoGrowFillFrom: (in category 'as yet unclassified') -----
  noCheckNoGrowFillFrom: anArray
  	"Add the elements of anArray except nils and associations with empty collections (or with only nils) to me assuming that I don't contain any of them, they are unique and I have more free space than they require."
  
  	tally := 0.
  	1 to: anArray size do:[ :i |
  		| association cleanedValue |
  		((association := anArray at: i) == nil or: [ 
  			(cleanedValue := association value copyWithout: nil) isEmpty ]) 
  				ifFalse: [
  					association value: cleanedValue.
  					array
+ 						at: (self scanForEmptySlotFor: association key)
- 						at: (self scanFor: association key)
  						put: association.
  					tally := tally + 1 ] ]!

Item was changed:

Item was changed:
  ----- Method: Dictionary>>associationsDo: (in category 'enumerating') -----
  associationsDo: aBlock 
  	"Evaluate aBlock for each of the receiver's elements (key/value 
  	associations)."
  
  	tally = 0 ifTrue: [ ^self].
+ 	1 to: array size do: [ :index |
+ 		| each |
+ 		(each := array at: index)
+ 			ifNotNil: [ aBlock value: each ] ]!
- 	array do: [ :each | each ifNotNil: [ aBlock value: each ] ]!

Item was changed:
  ----- Method: WeakSet>>growTo: (in category 'private') -----
  growTo: anInteger
  	"Grow the elements array and reinsert the old elements"
  
  	| oldElements |
- 
  	oldElements := array.
  	array := WeakArray new: anInteger.
  	array atAllPut: flag.
  	self noCheckNoGrowFillFrom: oldElements!

Item was changed:
  ----- Method: Set>>do: (in category 'enumerating') -----
  do: aBlock 
  
  	tally = 0 ifTrue: [ ^self ].
+ 	1 to: array size do: [ :index |
+ 		| each |
+ 		(each := array at: index)
+ 			ifNotNil: [ aBlock value: each ] ]!
- 	array do: [ :each | each ifNotNil: [ aBlock value: each ] ]!




More information about the Squeak-dev mailing list