[Pkg] The Trunk: Kernel-ul.626.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Sep 18 13:26:41 UTC 2011


Levente Uzonyi uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-ul.626.mcz

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

Name: Kernel-ul.626
Author: ul
Time: 18 September 2011, 3:18:04.315 pm
UUID: c917ec7b-b1ed-1849-bfb3-292cb3898035
Ancestors: Kernel-ul.625

MethodDictionary changes:
- fix: #compact shouldn't increase the load factor above 75% (see #sizeFor: on the class side)
- speed up #compact and #compactAllInstances by using #copyFrom: instead of #becomeForward: if the capacity of the dictionaries can't be reduced
- recategorized some class side methods
- use cascade in #at:put:

=============== Diff against Kernel-ul.625 ===============

Item was changed:
+ ----- Method: MethodDictionary class>>compactAllInstances (in category 'initialize-release') -----
- ----- Method: MethodDictionary class>>compactAllInstances (in category 'initialization') -----
  compactAllInstances
  
+ 	| instancesToExchange newInstances |
+ 	instancesToExchange := Array streamContents: [ :oldStream |
+ 		newInstances := Array streamContents: [ :newStream |
+ 			self allInstances do: [ :each |
+ 				| newInstance |
+ 				newInstance := each compactWithoutBecome.
+ 				newInstance capacity = each capacity 
+ 					ifTrue: [ each copyFrom: newInstance ]
+ 					ifFalse: [
+ 						oldStream nextPut: each.
+ 						newStream nextPut: newInstance ] ] ] ].
+ 	instancesToExchange elementsForwardIdentityTo: newInstances!
- 	| instances newInstances |
- 	instances := self allInstances asArray.
- 	newInstances := self allInstances collect: [ :each |
- 		each compactWithoutBecome ].
- 	instances elementsExchangeIdentityWith: newInstances!

Item was changed:
  ----- Method: MethodDictionary class>>new (in category 'instance creation') -----
  new
+ 	"Create a new instance with 32 slots. See the comment of #sizeFor: why the argument is 16."
- 	"Create a new instance with 32 slots."
  	
  	^self new: 16!

Item was changed:
  ----- Method: MethodDictionary class>>new: (in category 'instance creation') -----
+ new: numberOfElements
+ 	"Create an instance large enough to hold numberOfElements without growing. Note that the basic size must be a power of 2. It is VITAL (see grow) that size gets doubled if numberOfElements is a power of 2"
- new: nElements
- 	"Create a Dictionary large enough to hold nElements without growing.
- 	Note that the basic size must be a power of 2.
- 	It is VITAL (see grow) that size gets doubled if nElements is a power of 2"
  	
  	| size |
+ 	size := self sizeFor: numberOfElements.
- 	size := 1 bitShift: nElements highBit.
  	^(self basicNew: size) initialize: size!

Item was added:
+ ----- Method: MethodDictionary class>>sizeFor: (in category 'sizing') -----
+ sizeFor: numberOfElements
+ 	"Return the minimum capacity of a dictionary that can hold numberOfElements elements. At least 25% of the array must be empty and the return value must be a power of 2."
+ 
+ 	^1 bitShift: (numberOfElements * 4 // 3) highBit!

Item was changed:
  ----- Method: MethodDictionary>>at:put: (in category 'accessing') -----
  at: key put: value
  	"Set the value at key to be value."
  	
  	| index |
  	index := self scanFor: key.
  	(self basicAt: index)
  		ifNil: [
+ 			self
+ 				basicAt: index put: key;
+ 				atNewIndex: index put: value ]
- 			self basicAt: index put: key.
- 			self atNewIndex: index put: value ]
  		ifNotNil: [ 
  			(array at: index) flushCache.
  			array at: index put: value ].
  	^value!

Item was changed:
  ----- Method: MethodDictionary>>compact (in category 'private') -----
  compact
+ 	"Make sure that I have the highest possible load factor (between 37.5% and 75%)."
- 	"Make sure that I have the highest possible load factor (at least 50%)."
  	
  	| newInstance |
  	newInstance := self compactWithoutBecome.
+ 	newInstance capacity = self capacity
+ 		ifTrue: [ self copyFrom: newInstance ]
+ 		ifFalse: [ self becomeForward: newInstance ]!
- 	newInstance capacity = self capacity ifFalse: [
- 		self becomeForward: newInstance ]!

Item was changed:
  ----- Method: MethodDictionary>>compactWithoutBecome (in category 'private') -----
  compactWithoutBecome
+ 	"Return a copy of self which has the highest possible load factor (between 37.5% and 75%)."
- 	"Return a copy of self which has the highest possible load factor (at least 50%)."
  	
+ 	| newInstance |
+ 	newInstance := self species new: self size.
+ 	1 to: self basicSize do: [ :index | 
+ 		(self basicAt: index) ifNotNil: [ :key |
+ 			newInstance at: key put: (array at: index) ] ].
+ 	^newInstance!
- 	| newSelf |
- 	newSelf := self class new: self size.
- 	self keysAndValuesDo: [ :key :value |
- 		newSelf at: key put: value ].
- 	^newSelf!



More information about the Packages mailing list