[squeak-dev] The Trunk: Kernel-eem.676.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Mar 29 01:32:09 UTC 2012


Eliot Miranda uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-eem.676.mcz

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

Name: Kernel-eem.676
Author: eem
Time: 28 March 2012, 6:31:09.818 pm
UUID: 54422144-91c1-4c63-9fbe-8acb5733e35f
Ancestors: Kernel-eem.675

Neater simpler, correct implementtion of #once for the
current Squeak closure implemenation which lacks clean
blocks.

=============== Diff against Kernel-eem.675 ===============

Item was removed:
- ----- Method: BlockClosure>>becomeCached (in category 'private') -----
- becomeCached
- 	self become: ((CachedBlockClosure new: self size)
- 						outerContext: outerContext
- 						startpc: startpc
- 						numArgs: numArgs
- 						cachedValue: self value
- 						copiedValues: self)!

Item was removed:
- ----- Method: BlockClosure>>becomeUncached (in category 'private') -----
- becomeUncached
- 	"The receiver is already uncached."
- 	^self!

Item was changed:
  ----- Method: BlockClosure>>once (in category 'evaluating') -----
  once
+ 	"Evaluate the receiver exactly once, so that repeated evaluations
+ 	 answer exactly the same object as the first evaluation.  This
+ 	 allows one to intern values with the idiom
- 	"Answer and remember my value, answering exactly the same object in any further sends
- 	 of once or value until I become uncached.  This allows one to intern values with the idiom
  		myResourceMethod
+ 			^[expression] once"
+ 
+ 	| cache |
+ 	cache := self method
+ 				propertyValueAt: #onceCache
+ 				ifAbsent: [self method propertyValueAt: #onceCache put: Dictionary new].
+ 	^cache at: startpc ifAbsentPut: [self value]!
- 			^[expression] once.
- 	 The expression will be evaluated once and its result returned for any subsequent evaluations.
- 	 Originally by Travis Griggs, from whom we copy this idea with thanks."
- 	numArgs ~= 0 ifTrue:
- 		[self error: 'once should only be used with niladic blocks'].
- 	self becomeCached.
- 	^self once!

Item was removed:
- BlockClosure variableSubclass: #CachedBlockClosure
- 	instanceVariableNames: 'cachedValue'
- 	classVariableNames: ''
- 	poolDictionaries: ''
- 	category: 'Kernel-Methods'!
- 
- !CachedBlockClosure commentStamp: 'eem 7/22/2010 12:34' prior: 0!
- I'm a BlockClosure with an added instance variable for storing the once upon a time result of evaluating myself when I was simple BlockClosure. This is triggered by sending #once to a normal BlockClosure. Future sends of once will simply return this value rather than evaluate myself. When sent value, I revert back to a BlockClosure.  Originally by Travis Griggs, from whom we copy this idea with thanks.
- 
- Instance Variables
- 	cachedValue	<Object>
- 
- cachedValue
- 	- result of having sent value to myself when i was just a BlockClosure!

Item was removed:
- ----- Method: CachedBlockClosure>>becomeCached (in category 'private') -----
- becomeCached
- 	"The receiver is already cached."
- 	^self!

Item was removed:
- ----- Method: CachedBlockClosure>>becomeUncached (in category 'private') -----
- becomeUncached
- 	self become: (BlockClosure 
- 					outerContext: outerContext
- 					startpc: startpc
- 					numArgs: numArgs
- 					copiedValues: self)!

Item was removed:
- ----- Method: CachedBlockClosure>>once (in category 'evaluating') -----
- once
- 	^cachedValue!

Item was removed:
- ----- Method: CachedBlockClosure>>outerContext:startpc:numArgs:cachedValue:copiedValues: (in category 'initialize-release') -----
- outerContext: aContext startpc: aStartpc numArgs: argCount cachedValue: aValue copiedValues: anArrayOrNil
- 	cachedValue := aValue.
- 	super outerContext: aContext startpc: aStartpc numArgs: argCount copiedValues: anArrayOrNil!

Item was removed:
- ----- Method: CachedBlockClosure>>value (in category 'evaluating') -----
- value
- 	^cachedValue!



More information about the Squeak-dev mailing list