[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] class variables vs. class-instance variables
From: |
Paolo Bonzini |
Subject: |
[Help-smalltalk] class variables vs. class-instance variables |
Date: |
Fri, 16 Mar 2007 16:48:02 +0100 |
User-agent: |
Thunderbird 1.5.0.10 (Macintosh/20070221) |
Here's my current patch to remove many class variables.
Some of them could be considered bugs. Some of them
reduce duplicated code. Some are leftovers of class
variables that had *already* been converted to
class-instance variables, which sort of proves my point.
I'd appreciate another pair of eyes or two going
through it.
compiler/STCompiler.st | 2 -
compiler/STLoader.st | 2 -
compiler/STSymTable.st | 2 -
doc/gst.1 | 2 -
gtk/GtkDecl.st | 13 ++++---
java/JavaClassFiles.st | 66 ++++++++++++++++++-------------------
java/JavaRuntime.st | 49 ++++++++++++++--------------
java/java_lang_Runtime.st | 2 -
kernel/ContextPart.st | 2 -
kernel/DLD.st | 31 +++++++++--------
kernel/ObjDumper.st | 20 ++++++++---
kernel/PkgLoader.st | 29 +++++++++-------
kernel/Random.st | 18 +++++++---
kernel/Regex.st | 23 ++++++-------
kernel/VFS.st | 80 +++++++++++++++++++++++++++++++---------------
kernel/ValueAdapt.st | 15 ++++++--
libgst/dict.c | 7 ----
libgst/lib.c | 2 -
net/Base.st | 11 ++++--
net/MIME.st | 15 --------
net/URIResolver.st | 17 +++++----
net/httpd/WikiServer.st | 6 ++-
22 files changed, 236 insertions(+), 178 deletions(-)
* looking for address@hidden/smalltalk--devo--2.2--patch-277 to compare with
* comparing to address@hidden/smalltalk--devo--2.2--patch-277
M doc/gst.1
M kernel/Regex.st
M compiler/STCompiler.st
M compiler/STLoader.st
M compiler/STSymTable.st
M gtk/GtkDecl.st
M java/JavaClassFiles.st
M java/JavaRuntime.st
M java/java_lang_Runtime.st
M kernel/ContextPart.st
M kernel/DLD.st
M kernel/ObjDumper.st
M kernel/PkgLoader.st
M kernel/Random.st
M kernel/VFS.st
M kernel/ValueAdapt.st
M net/MIME.st
M net/URIResolver.st
M net/httpd/WikiServer.st
M libgst/lib.c
M libgst/dict.c
M net/Base.st
* modified files
--- orig/compiler/STCompiler.st
+++ mod/compiler/STCompiler.st
@@ -56,7 +56,7 @@ compile: methodDefNode for: aBehavior cl
STFakeCompiler subclass: #STCompiler
instanceVariableNames: 'node destClass symTable parser bytecodes depth
maxDepth isInsideBlock '
- classVariableNames: 'OneNode TrueNode FalseNode NilNode SuperVariable
SelfVariable ThisContextVariable DoitToken'
+ classVariableNames: 'OneNode TrueNode FalseNode NilNode SuperVariable
SelfVariable ThisContextVariable'
poolDictionaries: ''
category: 'System-Compiler'
!
--- orig/compiler/STLoader.st
+++ mod/compiler/STLoader.st
@@ -46,7 +46,7 @@ file-in.'!
STInterpreter subclass: #STClassLoader
instanceVariableNames: 'loadedClasses proxies currentClass
currentCategory currentNamespace'
- classVariableNames: 'EvaluationMethods'
+ classVariableNames: ''
poolDictionaries: 'STClassLoaderObjects'
category: 'System-Compiler'
!
--- orig/compiler/STSymTable.st
+++ mod/compiler/STSymTable.st
@@ -31,7 +31,7 @@
Object subclass: #STLiteralsTable
instanceVariableNames: 'map array'
- classVariableNames: 'UseUndeclared'
+ classVariableNames: ''
poolDictionaries: ''
category: 'System-Compiler'
!
--- orig/doc/gst.1
+++ mod/doc/gst.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.28.
-.TH SMALLTALK "1" "February 2007" "Smalltalk version 2.3" "User Commands"
+.TH SMALLTALK "1" "March 2007" "Smalltalk version 2.3" "User Commands"
.SH NAME
Smalltalk \- the GNU Smalltalk virtual machine
.SH DESCRIPTION
--- orig/gtk/GtkDecl.st
+++ mod/gtk/GtkDecl.st
@@ -67,10 +67,13 @@ Object subclass: #Atk
Object subclass: #GLib
instanceVariableNames: ''
- classVariableNames: 'GtkTypes'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Gtk'!
+GLib class
+ instanceVariableNames: 'gtkTypes'!
+
Object subclass: #GQuark
instanceVariableNames: ''
classVariableNames: ''
@@ -98,13 +101,13 @@ CObject variableWordSubclass: #GdkEvent
!GLib class methodsFor: 'registering GObject types'!
registerAllTypes
- GtkTypes isNil ifTrue: [ GtkTypes := OrderedCollection new ].
- GtkTypes do: [ :each | self register: each forType: each getType ]
+ gtkTypes isNil ifTrue: [ gtkTypes := OrderedCollection new ].
+ gtkTypes do: [ :each | self register: each forType: each getType ]
!
registerType: aClass
- GtkTypes isNil ifTrue: [ GtkTypes := OrderedCollection new ].
- GtkTypes addLast: aClass
+ gtkTypes isNil ifTrue: [ gtkTypes := OrderedCollection new ].
+ gtkTypes addLast: aClass
!
update: anObject
--- orig/java/JavaClassFiles.st
+++ mod/java/JavaClassFiles.st
@@ -266,7 +266,7 @@ Instance Variables:
JavaReader subclass: #JavaClassFileReader
instanceVariableNames: ''
- classVariableNames: ''
+ classVariableNames: 'ClassDirectories'
poolDictionaries: ''
category: 'Java-Class files'!
@@ -284,7 +284,7 @@ Subclasses must implement the following
JavaClassFileReader subclass: #JavaClassReader
instanceVariableNames: 'tag '
- classVariableNames: 'ClassDirectories'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Java-Class files'!
@@ -880,6 +880,36 @@ readFrom: aJavaAttributeReader name: att
^self new fileName: aJavaAttributeReader nextConstant
! !
+!JavaClassFileReader class methodsFor: 'class path'!
+
+classDirectories
+ ^ClassDirectories
+!
+
+classDirectories: aCollection
+ ClassDirectories := aCollection
+!
+
+classPath
+ ^self classDirectories fold: [ :a :b | a, ':', b ]
+!
+
+classPath: pathList
+ self classDirectories: (pathList subStrings: $:)
+!
+
+findClassFile: aClass
+ | path |
+ path := (aClass copyReplacing: $. withObject: $/) , '.class'.
+ self classDirectories isNil
+ ifTrue: [ self error: 'CLASSPATH not set' ].
+ self classDirectories do: [:dir || file |
+ file := File name: (Directory append: path to: dir).
+ file exists ifTrue: [ ^file ]].
+
+ ^nil
+! !
+
!JavaClassFileReader methodsFor: 'stream accessing'!
nextType
@@ -1160,36 +1190,6 @@ nameString: nameString typeString: typeS
type: (self typeFromString: typeString)
! !
-!JavaClassReader class methodsFor: 'class path'!
-
-classDirectories
- ^ClassDirectories
-!
-
-classDirectories: aCollection
- ClassDirectories := aCollection
-!
-
-classPath
- ^self classDirectories fold: [ :a :b | a, ':', b ]
-!
-
-classPath: pathList
- self classDirectories: (pathList subStrings: $:)
-!
-
-findClassFile: aClass
- | path |
- path := (aClass copyReplacing: $. withObject: $/) , '.class'.
- self classDirectories isNil
- ifTrue: [ self error: 'CLASSPATH not set' ].
- self classDirectories do: [:dir || file |
- file := File name: (Directory append: path to: dir).
- file exists ifTrue: [ ^file ]].
-
- ^nil
-! !
-
!JavaAttributeReader methodsFor: 'reading'!
rawBytes
@@ -1360,7 +1360,7 @@ addAttribute: aJavaAttribute
loadClass: aString
| file stream |
- file := JavaClassReader findClassFile: aString.
+ file := JavaClassFileReader findClassFile: aString.
file isNil ifTrue: [ self error: 'class not found: ', aString ].
"Transcript show: 'Loading '; show: aString; nl."
stream := file readStream.
--- orig/java/JavaRuntime.st
+++ mod/java/JavaRuntime.st
@@ -47,10 +47,13 @@ methods called back by the translated by
Object subclass: #JavaMonitor
instanceVariableNames: 'semaphore process count waitSemaphores '
- classVariableNames: 'Monitors Mutex LastMonitor LastObject'
+ classVariableNames: ''
poolDictionaries: ''
category: ''!
+JavaMonitor class
+ instanceVariableNames: 'monitors mutex lastMonitor lastObject'!
+
ArrayedCollection variable: #int8 subclass: #JavaByteArray
instanceVariableNames: ''
classVariableNames: ''
@@ -165,8 +168,8 @@ be kept entirely with class variables, s
!JavaMonitor class methodsFor: 'initialization'!
initialize
- Mutex := Semaphore forMutualExclusion.
- Monitors := WeakKeyIdentityDictionary new!
+ mutex := Semaphore forMutualExclusion.
+ monitors := WeakKeyIdentityDictionary new!
!JavaMonitor class methodsFor: 'private'!
@@ -185,39 +188,39 @@ monitorFor: anObject
between the time the monitor is entered and the time the monitor is
exited."
- LastObject == anObject ifTrue: [ ^LastMonitor ].
+ lastObject == anObject ifTrue: [ ^lastMonitor ].
- LastObject := anObject.
- LastMonitor := Monitors at: anObject ifAbsent: [ nil ].
- ^LastMonitor isNil
- ifFalse: [ LastMonitor ]
- ifTrue: [ Monitors at: anObject put: (LastMonitor := self new)]! !
+ lastObject := anObject.
+ lastMonitor := monitors at: anObject ifAbsent: [ nil ].
+ ^lastMonitor isNil
+ ifFalse: [ lastMonitor ]
+ ifTrue: [ monitors at: anObject put: (lastMonitor := self new)]! !
!JavaMonitor class methodsFor: 'locking'!
enter: anObject
"Of course, we wait on the monitor *after* relinquishing the mutex."
| monitor |
- Mutex wait.
+ mutex wait.
monitor := self monitorFor: anObject.
- Mutex signal.
+ mutex signal.
monitor wait!
exit: anObject
"Note that we signal the monitor *before* relinquishing the mutex."
- Mutex wait.
+ mutex wait.
(self monitorFor: anObject) signal.
- Mutex signal!
+ mutex signal!
notifyAll: anObject
- Mutex wait.
+ mutex wait.
(self monitorFor: anObject) notifyAll.
- Mutex signal!
+ mutex signal!
notify: anObject
- Mutex wait.
+ mutex wait.
(self monitorFor: anObject) notify.
- Mutex signal!
+ mutex signal!
waitOn: anObject timeout: msec
| monitor count process waitSemaphores sema |
@@ -225,12 +228,12 @@ waitOn: anObject timeout: msec
sema := Semaphore new.
"Grab the monitor, unlock it and register the semaphore we'll wait on."
- Mutex wait.
+ mutex wait.
monitor := (self monitorFor: anObject).
count := monitor unlock.
waitSemaphores := monitor waitSemaphores.
waitSemaphores addLast: sema.
- Mutex signal.
+ mutex signal.
"If there's a timeout, start a process to exit the wait anticipatedly."
msec > 0 ifTrue: [
@@ -243,10 +246,10 @@ waitOn: anObject timeout: msec
monitor afterwards (see also #exit:, which waits after getting the
monitor and relinquishing the mutex)."
process notNil ifTrue: [
- Mutex wait.
+ mutex wait.
waitSemaphores remove: sema ifAbsent: [].
process terminate.
- Mutex signal ].
+ mutex signal ].
monitor lock: count!
@@ -1066,11 +1069,11 @@ load: class
bootstrap
| classPath |
Bootstrapped := false.
- JavaClassReader classDirectories isNil
+ JavaClassFileReader classDirectories isNil
ifTrue: [
classPath := Smalltalk getenv: 'CLASSPATH'.
classPath isNil ifTrue: [ self error: 'CLASSPATH not set' ].
- JavaClassReader classPath: classPath ].
+ JavaClassFileReader classPath: classPath ].
Transcript show: 'Installing native methods...'; nl.
self installNativeMethods.
--- orig/java/java_lang_Runtime.st
+++ mod/java/java_lang_Runtime.st
@@ -141,7 +141,7 @@ java_lang_Runtime_insertSystemProperties
put value: 'java.vm.specification.name' value: 'Java(tm) Virtual
Machine Specification'.
put value: 'java.vm.specification.vendor' value: 'Sun Microsystems Inc.'.
- put value: 'java.class.path' value: JavaClassReader classPath.
+ put value: 'java.class.path' value: JavaClassFileReader classPath.
put value: 'java.home' value: Directory image.
put value: 'os.name' value: os.
put value: 'os.arch' value: cpu.
--- orig/kernel/ContextPart.st
+++ mod/kernel/ContextPart.st
@@ -34,7 +34,7 @@
Object variableSubclass: #ContextPart
instanceVariableNames: 'parent nativeIP ip sp receiver method '
- classVariableNames: 'UnwindPoints'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Language-Implementation'
!
--- orig/kernel/DLD.st
+++ mod/kernel/DLD.st
@@ -144,11 +144,14 @@ do: aBlock
Object subclass: #DLD
instanceVariableNames: ''
- classVariableNames: 'LibraryList LibraryStream ModuleList'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Language-C interface'
!
+DLD class
+ instanceVariableNames: 'libraryList libraryStream moduleList'!
+
DLD comment: '...and Gandalf said:
``Many folk like to know beforehand what is to be set on the
table; but those who have laboured to prepare the feast like
@@ -214,7 +217,7 @@ primDefineExternFunc: aFuncName
whether the linkage was successful. It should not be overridden."
| couldNotLink |
- LibraryStream do: [ :lib || funcAddr |
+ libraryStream do: [ :lib || funcAddr |
lib value notNil
ifTrue: [
funcAddr := self library: lib value getFunc: aFuncName.
@@ -230,9 +233,9 @@ primDefineExternFunc: aFuncName
initialize
"Private - Initialize the receiver's class variables"
- LibraryList := OrderedCollection new.
- LibraryStream := RoundRobinStream on: LibraryList readStream.
- ModuleList := OrderedCollection new.
+ libraryList := OrderedCollection new.
+ libraryStream := RoundRobinStream on: libraryList readStream.
+ moduleList := OrderedCollection new.
ObjectMemory addDependent: DLD
!
@@ -241,11 +244,11 @@ update: aspect
all the externally defined functions"
| notLoaded |
aspect == #returnFromSnapshot ifFalse: [ ^self ].
- LibraryList do: [ :lib | lib value: (self linkFile: lib key) ].
+ libraryList do: [ :lib | lib value: (self linkFile: lib key) ].
notLoaded := WriteStream on: Array new.
- ModuleList do: [ :each |
+ moduleList do: [ :each |
(self linkFile: each) isNil ifTrue: [ notLoaded nextPut: each ]
].
@@ -257,20 +260,20 @@ update: aspect
libraryList
"Answer a copy of the search path of libraries to be used by DLD"
- ^LibraryList copy
+ ^libraryList copy
!
moduleList
"Answer a copy of the modules reloaded when the image is started"
- ^ModuleList copy
+ ^moduleList copy
!
addLibrary: library
"Add library to the search path of libraries to be used by DLD."
- (LibraryList anySatisfy: [ :anAssociation | anAssociation key = library ])
+ (libraryList anySatisfy: [ :anAssociation | anAssociation key = library ])
ifFalse: [
- LibraryList add: library -> (self linkFile: library).
- LibraryStream := RoundRobinStream on: LibraryList readStream ].
+ libraryList add: library -> (self linkFile: library).
+ libraryStream := RoundRobinStream on: libraryList readStream ].
!
addModule: library
@@ -279,12 +282,12 @@ addModule: library
but the library will not be put in the search path used whenever
a C function is requested but not registered."
- (ModuleList includes: library) ifFalse: [
+ (moduleList includes: library) ifFalse: [
(self linkFile: library) isNil
ifTrue: [
SystemExceptions.CInterfaceError
signal: 'requested module ', library, ' was not found' ]
- ifFalse: [ ModuleList add: library ]
+ ifFalse: [ moduleList add: library ]
]
! !
--- orig/kernel/ObjDumper.st
+++ mod/kernel/ObjDumper.st
@@ -69,10 +69,13 @@ NullProxy subclass: #VersionableObjectPr
AlternativeObjectProxy subclass: #SingletonProxy
instanceVariableNames: ''
- classVariableNames: 'Singletons'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Streams-Files'!
+SingletonProxy class
+ instanceVariableNames: 'singletons'!
+
ObjectDumper comment: 'I''m not part of a normal Smalltalk system, but most
Smalltalks provide a similar feature: that is, support for storing objects
in a binary format; there are many advantages in using me instead of #storeOn:
@@ -945,6 +948,14 @@ dumpTo: anObjectDumper
! !
+!SingletonProxy class methodsFor: 'private'!
+
+singletons
+ ^singletons isNil
+ ifTrue: [ singletons := IdentityDictionary new ]
+ ifFalse: [ singletons ]
+! !
+
!SingletonProxy class methodsFor: 'accessing'!
acceptUsageForClass: aClass
@@ -953,8 +964,7 @@ acceptUsageForClass: aClass
| singleton |
singleton := aClass someInstance.
singleton nextInstance isNil ifFalse: [ ^false ].
- Singletons isNil ifTrue: [ Singletons := IdentityDictionary new ].
- Singletons at: aClass put: singleton.
+ self singletons at: aClass put: singleton.
^true
! !
@@ -966,7 +976,7 @@ on: anObject
stores the class and restores the object by looking into
a dictionary of class -> singleton objects."
- (Singletons includesKey: anObject class)
+ (self singletons includesKey: anObject class)
ifTrue: [ ^super on: anObject class ].
self error: 'class not registered within SingletonProxy'
@@ -980,7 +990,7 @@ object
#reconstructOriginalObject message, and the resulting
object is sent the #postLoad message."
- ^Singletons at: super object ifAbsent: [
+ ^self singletons at: super object ifAbsent: [
self error: 'class not registered within SingletonProxy' ]
! !
--- orig/kernel/PkgLoader.st
+++ mod/kernel/PkgLoader.st
@@ -46,11 +46,14 @@ XML.'!
Object subclass: #PackageLoader
instanceVariableNames: ''
- classVariableNames: 'Packages LoadDate IgnoreCallouts'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Language-Packaging'
!
+PackageLoader class
+ instanceVariableNames: 'packages loadDate ignoreCallouts'!
+
PackageLoader comment:
'I am not part of a standard Smalltalk system. I provide methods for
retrieving package information from an XML file and to load packages
@@ -310,7 +313,7 @@ fileIn
packageAt: package
"Answer a Package object for the given package"
self refreshDependencies.
- ^Packages at: package asString
+ ^packages at: package asString
!
directoryFor: package
@@ -368,17 +371,18 @@ prerequisitesFor: package
ignoreCallouts
"Answer whether unavailable C callouts must generate errors or not."
- ^IgnoreCallouts
+ ignoreCallouts isNil ifTrue: [ ignoreCallouts := false ].
+ ^ignoreCallouts
!
ignoreCallouts: aBoolean
"Set whether unavailable C callouts must generate errors or not."
- IgnoreCallouts := aBoolean
+ ignoreCallouts := aBoolean
!
flush
"Set to reload the `packages.xml' file the next time it is needed."
- LoadDate := nil
+ loadDate := nil
!
refreshDependencies
@@ -393,12 +397,12 @@ refreshDependencies
searched. For a packages.xml directory in the local image directory,
finally, only directory 3 is searched."
| state |
- LoadDate isNil ifFalse: [
+ loadDate isNil ifFalse: [
self stillValid ifTrue: [ ^self ]
].
- LoadDate := Date dateAndTimeNow.
- Packages := LookupTable new.
+ loadDate := Date dateAndTimeNow.
+ packages := LookupTable new.
self
processPackageFile: self packageFileName
baseDirectories: { Directory userBase. Directory kernel, '/..' }.
@@ -498,7 +502,7 @@ hasCallout: feature
isLoadable: feature
"Private - Answer whether the packages file includes an entry for
`feature'"
self refreshDependencies.
- ^Packages includesKey: feature asString
+ ^packages includesKey: feature asString
! !
@@ -520,7 +524,7 @@ printXmlOn: aStream
"Print the XML source code for the information that the PackageLoader
holds on aStream."
aStream nextPutAll: '<packages>'.
- Packages keys asSortedCollection do: [ :each |
+ packages keys asSortedCollection do: [ :each |
(self packageAt: each) printOn: aStream.
].
aStream nextPutAll: '</packages>'
@@ -586,7 +590,7 @@ processPackageFile: fileName baseDirecto
tag = 'library' ifTrue: [ package libraries add: cdata ] ifFalse: [
tag = 'package' ifTrue: [
(package baseDirs: baseDirs)
- ifTrue: [ Packages at: package name put: package ]]
ifFalse: [
+ ifTrue: [ packages at: package name put: package ]]
ifFalse: [
tag = 'built-file' ifTrue: [ package builtFiles add: cdata ]
ifFalse: [
tag = 'callout' ifTrue: [ package callouts add: cdata ]]]]]]]]]]]].
cdata := nil.
@@ -608,8 +612,7 @@ stillValid
^{ self packageFileName. self userPackageFileName. self
localPackageFileName }
allSatisfy: [ :name || file |
file := File name: name.
- file exists not or: [ file lastModifyTime < LoadDate ]
+ file exists not or: [ file lastModifyTime < loadDate ]
]
! !
-PackageLoader ignoreCallouts: false!
--- orig/kernel/Random.st
+++ mod/kernel/Random.st
@@ -34,11 +34,14 @@
Stream subclass: #Random
instanceVariableNames: 'seed'
- classVariableNames: 'Source'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Streams'
!
+Random class
+ instanceVariableNames: 'source'!
+
Random comment: "Here's a random comment :-)"
'My instances are generator streams that produce random numbers, which are
floating point values between 0 and 1.'!
@@ -61,16 +64,21 @@ new
!Random class methodsFor: 'shortcuts'!
+source
+ "Return a standard source of random numbers."
+ ^source isNil
+ ifTrue: [ source := self new ]
+ ifFalse: [ source ]
+!
+
next
"Return a random number between 0 and 1 (excluded)"
- Source isNil ifTrue: [ Source := self new ].
- ^Source next
+ ^self source next
!
between: low and: high
"Return a random integer between the given extrema"
- Source isNil ifTrue: [ Source := self new ].
- ^Source between: low and: high
+ ^self source between: low and: high
! !
--- orig/kernel/Regex.st
+++ mod/kernel/Regex.st
@@ -77,11 +77,14 @@ RegexResults subclass: #MatchingRegexRes
RegexResults subclass: #FailedMatchRegexResults
instanceVariableNames: ''
- classVariableNames: 'NotMatched'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Collections-Text'
!
+FailedMatchRegexResults class
+ instanceVariableNames: 'uniqueInstance'!
+
Namespace current: Smalltalk!
!RegexResults methodsFor: 'testing'!
@@ -172,12 +175,10 @@ intervalAt: anIndex
!Kernel.FailedMatchRegexResults class methodsFor: 'private'!
-initialize
- NotMatched := self new
-!
-
-notMatched
- ^NotMatched
+uniqueInstance
+ ^uniqueInstance isNil
+ ifTrue: [ uniqueInstance := self new ]
+ ifFalse: [ uniqueInstance ]
! !
!Kernel.FailedMatchRegexResults methodsFor: 'testing'!
@@ -411,7 +412,7 @@ asRegex
| regs |
regs := self searchRegexInternal: pattern from: 1 to: self size.
^regs isNil
- ifTrue: [ Kernel.FailedMatchRegexResults notMatched ]
+ ifTrue: [ Kernel.FailedMatchRegexResults uniqueInstance ]
ifFalse: [ regs ]
!
@@ -421,7 +422,7 @@ searchRegex: pattern
| regs |
regs := self searchRegexInternal: pattern from: 1 to: self size.
^regs isNil
- ifTrue: [ Kernel.FailedMatchRegexResults notMatched ]
+ ifTrue: [ Kernel.FailedMatchRegexResults uniqueInstance ]
ifFalse: [ regs ]
!
@@ -432,7 +433,7 @@ searchRegex: pattern startingAt: anIndex
| regs |
regs := self searchRegexInternal: pattern from: anIndex to: self size.
^regs isNil
- ifTrue: [ Kernel.FailedMatchRegexResults notMatched ]
+ ifTrue: [ Kernel.FailedMatchRegexResults uniqueInstance ]
ifFalse: [ regs ]
!
@@ -443,7 +444,7 @@ searchRegex: pattern from: from to: to
| regs |
regs := self searchRegexInternal: pattern from: from to: to.
^regs isNil
- ifTrue: [ Kernel.FailedMatchRegexResults notMatched ]
+ ifTrue: [ Kernel.FailedMatchRegexResults uniqueInstance ]
ifFalse: [ regs ]
!
--- orig/kernel/VFS.st
+++ mod/kernel/VFS.st
@@ -58,11 +58,14 @@ up being on disk when they are opened fo
RealFileHandler subclass: #DecodedFileHandler
instanceVariableNames: 'realFileName'
- classVariableNames: 'FileTypes'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Streams-Files'
!
+DecodedFileHandler class
+ instanceVariableNames: 'fileTypes'!
+
DecodedFileHandler comment: 'DecodedFileHandler handles
virtual filesystems that take a file that is on-disk, run a
command on it, and then read from the result.'!
@@ -74,6 +77,9 @@ RealFileHandler subclass: #ArchiveFileHa
category: 'Streams-Files'
!
+ArchiveFileHandler class
+ instanceVariableNames: 'activePaths'!
+
ArchiveFileHandler comment: 'ArchiveFileHandler handles
virtual filesystems that have a directory structure of
their own. The directories and files in the archive are
@@ -84,11 +90,14 @@ on them, to extract them to a real file,
ArchiveFileHandler subclass: #ExternalArchiveFileHandler
instanceVariableNames: 'command topLevelFiles allFiles extractedFiles'
- classVariableNames: 'ActivePaths FileTypes'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Streams-Files'
!
+ExternalArchiveFileHandler class
+ instanceVariableNames: 'fileTypes'!
+
ExternalArchiveFileHandler comment: 'ExternalArchiveFileHandler
allows for easy implementation of archive files (for example,
transparent unzipping and untarring) with a single shell script.
@@ -614,10 +623,16 @@ do: aBlock
!DecodedFileHandler class methodsFor: 'registering'!
-initialize
- "Initialize the default virtual filesystems and the associated
+fileTypes
+ "Return the valid virtual filesystems and the associated
filter commands."
- FileTypes := LookupTable new
+ fileTypes isNil ifTrue: [ fileTypes := self defaultFileTypes ].
+ ^fileTypes!
+
+defaultFileTypes
+ "Return the default virtual filesystems and the associated
+ filter commands."
+ ^LookupTable new
at: 'Z' put: 'compress -cf < %1 > %2';
at: 'uZ' put: 'zcat -f < %1 > %2';
at: 'gz' put: 'gzip -cf < %1 > %2';
@@ -639,7 +654,7 @@ fileSystems
gzipped tar archive out of a directory), #nop (do nothing, used for
testing) and #strings (use the `strings' utility to extract printable
strings from a file)."
- ^FileTypes keys!
+ ^self fileTypes keys!
vfsFor: file name: fsName subPath: subPath
"Create a temporary file and use it to construct the contents of the given
@@ -649,7 +664,7 @@ vfsFor: file name: fsName subPath: subPa
subPath isNil
ifFalse: [ SystemExceptions.FileError signal: 'not a tree-shaped
filesystem' ].
- command := FileTypes at: fsName.
+ command := self fileTypes at: fsName.
temp := FileStream openTemporaryFile: Directory temporary, '/vfs'.
Smalltalk system: (command bindWith: file with: temp name).
^self new name: file realFileName: temp name! !
@@ -678,6 +693,30 @@ release
self primUnlink: realFileName.
realFileName := nil.
super release! !
+
+
+!ArchiveFileHandler class methodsFor: 'private'!
+
+activePaths
+ "Answer a dictionary that stores the currently opened archive file
+ members, to avoid extracting members multiple times. Might be
+ worthwhile to push it to the superclass."
+ activePaths isNil ifTrue: [ activePaths := WeakValueLookupTable new ].
+ ^activePaths!
+
+vfsFor: file name: fsName subPath: subPath
+ "Create a temporary file and use it to construct the contents of the given
+ file, under the virtual filesystem fsName."
+ subPath isNil
+ ifFalse: [ ^(self vfsFor: file name: fsName subPath: nil) at: subPath ].
+
+ ^self activePaths at: (fsName -> file) ifAbsentPut: [
+ self vfsFor: file name: fsName ]!
+
+release
+ activePaths := nil.
+ super release! !
+
!ArchiveFileHandler methodsFor: 'querying'!
@@ -777,8 +816,7 @@ fileSystems
subdirectory of the image directory, of the parent of the kernel
directory and (if the image is not the global installed image)
of the `.st' directory in the home directory."
- ActivePaths := WeakValueLookupTable new.
- FileTypes := LookupTable new.
+ fileTypes := LookupTable new.
[ self fileSystemsIn: Directory kernel, '/../vfs' ]
on: Error do: [ :ex | ex return ].
[ self fileSystemsIn: Directory userBase, '/vfs' ]
@@ -787,7 +825,7 @@ fileSystems
[ self fileSystemsIn: Directory image, '/vfs' ]
on: Error do: [ :ex | ex return ] ].
- ^FileTypes keys asSet!
+ ^fileTypes keys asSet!
fileSystemsIn: path
"Registers the executable files in the given directory to be used
@@ -797,30 +835,20 @@ fileSystemsIn: path
dir exists ifFalse: [ ^self ].
dir do: [ :each |
(File isExecutable: path, '/', each)
- ifTrue: [ FileTypes at: each put: path, '/', each ]
+ ifTrue: [ fileTypes at: each put: path, '/', each ]
]!
release
"Avoid that paths stay in the image file"
- FileTypes := nil.
+ fileTypes := nil.
super release!
-vfsFor: file name: fsName subPath: subPath
+vfsFor: file name: fsName
"Create a temporary file and use it to construct the contents of the given
file, under the virtual filesystem fsName."
- subPath isNil ifFalse: [
- ^(self vfsFor: file name: fsName subPath: nil)
- at: subPath
- ].
-
- ^ActivePaths at: (fsName -> file) ifAbsentPut: [
- | command temp |
- command := FileTypes at: fsName.
- self new
- name: file;
- command: command
- ]! !
-
+ ^self new
+ name: file;
+ command: (fileTypes at: fsName)! !
!ExternalArchiveFileHandler methodsFor: 'members'!
--- orig/kernel/ValueAdapt.st
+++ mod/kernel/ValueAdapt.st
@@ -82,6 +82,9 @@ ValueAdaptor subclass: #NullValueHolder
category: 'Language-Data types'
!
+NullValueHolder class
+ instanceVariableNames: 'uniqueInstance'!
+
NullValueHolder comment:
'I pretend to store my value in a variable, but I don''t actually.
You can use the only instance of my class (returned by `ValueHolder null'')
@@ -95,6 +98,13 @@ new
^self shouldNotImplement
!
+uniqueInstance
+ "Answer the sole instance of NullValueHolder"
+ ^uniqueInstance isNil
+ ifTrue: [ uniqueInstance := self basicNew ]
+ ifFalse: [ uniqueInstance ]
+! !
+
!NullValueHolder methodsFor: 'accessing'!
value: anObject
@@ -109,7 +119,7 @@ value
ValueAdaptor subclass: #ValueHolder
instanceVariableNames: 'value'
- classVariableNames: 'Null'
+ classVariableNames: ''
poolDictionaries: ''
category: 'Language-Data types'
!
@@ -148,8 +158,7 @@ new
null
"Answer the sole instance of NullValueHolder"
- Null isNil ifTrue: [ Null := NullValueHolder basicNew ].
- ^Null
+ ^NullValueHolder uniqueInstance
!
with: anObject
--- orig/libgst/dict.c
+++ mod/libgst/dict.c
@@ -145,7 +145,6 @@ OOP _gst_permission_class = NULL;
OOP _gst_positionable_stream_class = NULL;
OOP _gst_process_class = NULL;
OOP _gst_processor_scheduler_class = NULL;
-OOP _gst_random_class = NULL;
OOP _gst_read_stream_class = NULL;
OOP _gst_read_write_stream_class = NULL;
OOP _gst_root_namespace_class = NULL;
@@ -622,10 +621,6 @@ static const class_definition class_info
ISP_FIXED, true, 2,
"FileStream", "writePtr writeEnd", "Verbose Record Includes", NULL },
- {&_gst_random_class, &_gst_stream_class,
- ISP_FIXED, false, 1,
- "Random", "seed", "Source", NULL },
-
{&_gst_undefined_object_class, &_gst_object_class,
ISP_FIXED, true, 0,
"UndefinedObject", NULL, NULL, NULL },
@@ -683,7 +678,7 @@ static const class_definition class_info
{&_gst_context_part_class, &_gst_object_class,
ISP_POINTER, true, 6,
"ContextPart", "parent nativeIP ip sp receiver method ",
- "UnwindPoints", NULL },
+ NULL, NULL },
{&_gst_method_context_class, &_gst_context_part_class,
ISP_POINTER, true, 1,
--- orig/libgst/lib.c
+++ mod/libgst/lib.c
@@ -370,7 +370,6 @@ static const char standard_files[] = {
"RWStream.st\0"
"ByteStream.st\0"
"TokenStream.st\0"
- "Random.st\0"
"UndefObject.st\0"
"ProcSched.st\0"
"Delay.st\0"
@@ -393,6 +392,7 @@ static const char standard_files[] = {
"ObjMemory.st\0"
/* More core classes */
+ "Random.st\0"
"Transcript.st\0"
"RecursionLock.st\0"
"Point.st\0"
--- orig/net/Base.st
+++ mod/net/Base.st
@@ -57,10 +57,13 @@ Instance Variables:
Object subclass: #NetEnvironment
instanceVariableNames: 'debugStream debugCategories debugClasses trace
logFileName '
- classVariableNames: 'Environment '
+ classVariableNames: ''
poolDictionaries: ''
category: 'NetClients-Framework'!
+NetEnvironment class
+ instanceVariableNames: 'uniqueInstance'!
+
NetEnvironment comment:
nil!
@@ -226,9 +229,9 @@ username: aString
default
- ^ Environment isNil
- ifTrue: [ Environment := self new ]
- ifFalse: [ Environment ].! !
+ ^uniqueInstance isNil
+ ifTrue: [ uniqueInstance := self new ]
+ ifFalse: [ uniqueInstance ].! !
!NetEnvironment methodsFor: 'accessing'!
--- orig/net/MIME.st
+++ mod/net/MIME.st
@@ -78,7 +78,7 @@ Instance Variables:
MessageElement subclass: #HeaderField
instanceVariableNames: 'name source '
- classVariableNames: 'Registry '
+ classVariableNames: ''
poolDictionaries: ''
category: 'NetClients-MIME'!
@@ -102,10 +102,6 @@ This reads field''s name, find an approp
Instance Variables:
name <String> comment
source <String> comment
-
-
-Class Variables:
- Registry <IdentityDictionary key: String value: HeaderField class>
comment
'!
SimpleScanner subclass: #MimeEncodedWordCoDec
@@ -1219,14 +1215,6 @@ printOn: stream
comment notNil ifTrue: [self printCommentOn: stream]! !
-!HeaderField class methodsFor: 'class initialization'!
-
-initialize
- self resetRegistry.!
-
-resetRegistry
- Registry := IdentityDictionary new: 5.! !
-
!HeaderField class methodsFor: 'instance creation'!
name: aname
@@ -2934,7 +2922,6 @@ printValueOn: aStream
]! !
SimpleScanner initialize!
-HeaderField initialize!
RFC822Scanner initialize!
Namespace current: Smalltalk!
--- orig/net/URIResolver.st
+++ mod/net/URIResolver.st
@@ -57,10 +57,13 @@ nil!
Object subclass: #UserProfileSettings
instanceVariableNames: 'settings '
- classVariableNames: 'Default '
+ classVariableNames: ''
poolDictionaries: ''
category: 'NetClients-URIResolver'!
+UserProfileSettings class
+ instanceVariableNames: 'default'!
+
UserProfileSettings comment:
nil!
@@ -1420,14 +1423,12 @@ guessedContentType
!UserProfileSettings class methodsFor: 'accessing'!
default
- ^Default! !
-
-!UserProfileSettings class methodsFor: 'class initialization'!
-
-initialize
- "UserProfileSettings initialize"
+ ^default isNil
+ ifTrue: [ default := self new ]
+ ifFalse: [ default ]!
- Default := self new! !
+default: aSettingsObject
+ default := aSettingsObject! !
!UserProfileSettings class methodsFor: 'instance creation'!
--- orig/net/httpd/WikiServer.st
+++ mod/net/httpd/WikiServer.st
@@ -1048,10 +1048,14 @@ closeTableRow
contentStream position: pos!
processNextChar
+ | selector |
lastChar := currentChar.
currentChar := contentStream next.
- ^self perform: (ParseTable at: (currentChar asciiValue + 1))!
+ selector := ParseTable at: (currentChar asciiValue + 1).
+ ^selector isNil
+ ifTrue: [ self addCurrentChar ]
+ ifFalse: [ self perform: selector ]!
processDot
self atLineStart ifFalse: [ ^self addCurrentChar].
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-smalltalk] class variables vs. class-instance variables,
Paolo Bonzini <=