[squeak-dev] The Trunk: Files-ul.105.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Mar 17 01:05:31 UTC 2011
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.105.mcz
==================== Summary ====================
Name: Files-ul.105
Author: ul
Time: 17 March 2011, 1:27:16.073 am
UUID: 4ce2e9e4-7ccd-284f-bdaa-546c404b6727
Ancestors: Files-ul.104
- added a new method CurrentReadOnlySourceFiles class >> #cacheDuring: to avoid writing boilerplate code
- updated class comment
- categorized methods
- RemoteString >> #text uses CurrentReadOnlySourceFiles
=============== Diff against Files-ul.104 ===============
Item was changed:
Exception subclass: #CurrentReadOnlySourceFiles
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Files-System'!
+ !CurrentReadOnlySourceFiles commentStamp: 'ul 3/17/2011 01:17' prior: 0!
- !CurrentReadOnlySourceFiles commentStamp: 'ul 3/16/2011 23:08' prior: 0!
I'm useful to avoid the creation of several read-only copies of the source files. Use me instead of SourceFiles in your code when you need a read-only copy, like here:
CurrentReadOnlySourceFiles at: 1.
To reuse the source files, surround your code the following way:
+ CurrentReadOnlySourceFiles cacheDuring: [
+ <your code here using CurrentReadOnlySourceFiles> ]
- | currentReadOnlySourceFiles |
- ...
- [ <your code using the source files> ]
- on: CurrentReadOnlySourceFiles
- do: [ :ex |
- ex resume: (currentReadOnlySourceFiles
- ifNil: [ currentReadOnlySourceFiles := ex defaultAction ]) ].
- ...
+ Note that it's still better performance wise to store the source files in a variable in your code if you need them more than once, than throwing many exceptions.!
- Note that it's still better to store the source files in a variable in your code, than throwing many exceptions performance wise.!
Item was changed:
+ ----- Method: CurrentReadOnlySourceFiles classSide>>at: (in category 'act like SourceFiles') -----
- ----- Method: CurrentReadOnlySourceFiles classSide>>at: (in category 'as yet unclassified') -----
at: sourceFileIndex
^self signal at: sourceFileIndex!
Item was added:
+ ----- Method: CurrentReadOnlySourceFiles classSide>>cacheDuring: (in category 'caching') -----
+ cacheDuring: aBlock
+ "Cache the read only source files on the first request and use them on subsequent requests during the evaluation of aBlock."
+
+ | currentReadOnlySouceFiles |
+ currentReadOnlySouceFiles := nil.
+ ^aBlock
+ on: self
+ do: [ :exception |
+ exception resume: (currentReadOnlySouceFiles ifNil: [
+ currentReadOnlySouceFiles := exception defaultAction ]) ]!
Item was changed:
+ ----- Method: CurrentReadOnlySourceFiles>>defaultAction (in category 'handling') -----
- ----- Method: CurrentReadOnlySourceFiles>>defaultAction (in category 'as yet unclassified') -----
defaultAction
"Return a read-only copy of SourceFiles."
^SourceFiles collect: [ :each |
each ifNotNil: [
[ each readOnlyCopy ]
on: FileDoesNotExistException
do: [ :ex | nil "file does not exist happens in secure mode" ] ] ]!
Item was changed:
----- Method: RemoteString>>text (in category 'accessing') -----
text
"Answer the receiver's string asText if remote files are enabled."
| theFile |
+ theFile := (CurrentReadOnlySourceFiles at: (sourceFileNumber ifNil: [ ^nil ])) ifNil: [ ^nil ].
- theFile := (SourceFiles at: (sourceFileNumber ifNil: [ ^nil ])) ifNil: [ ^nil ].
theFile size < filePositionHi ifTrue: [
self error: 'RemoteString past end of file' ].
^theFile
position: filePositionHi;
nextChunkText!
More information about the Squeak-dev
mailing list
|