The Trunk: System-ul.384.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: System-ul.384.mcz

commits-2
Levente Uzonyi uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-ul.384.mcz

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

Name: System-ul.384
Author: ul
Time: 8 October 2010, 9:36:43.893 pm
UUID: 32f7b300-0184-8d4c-b55c-6a49cc6e7199
Ancestors: System-nice.382

- a proposal to speed up SystemDictionary >> #hasBindingThatBeginsWith: which is responsible for the slowdown of Shout and E/OCompletion when the code contains undefined variables.

=============== Diff against System-nice.382 ===============

Item was changed:
  IdentityDictionary subclass: #SystemDictionary
+ instanceVariableNames: 'cachedClassNames cachedNonClassNames'
- instanceVariableNames: 'cachedClassNames'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'System-Support'!
 
  !SystemDictionary commentStamp: 'nice 3/6/2010 21:56' prior: 0!
  I represent a special dictionary used as global namespace for class names :
 
  Smalltalk globals classNames.
 
  and for traits too:
 
  Smalltalk globals traitNames.
 
  and a few other globals:
 
  (Smalltalk globals keys reject: [:k | (Smalltalk globals at: k) isBehavior])
  collect: [:k | k -> (Smalltalk globals at: k) class].
 
  As the above example let you guess, the global namespace of Smalltalk system is accessed through:
 
  Smalltalk globals.!

Item was changed:
  ----- Method: SystemDictionary>>classNames (in category 'classes and traits') -----
  classNames
+ "Answer a sorted collection of all class names. Use the return value of #fillCaches to avoid concurrency issues."
+
+ ^cachedClassNames ifNil: [ self fillCaches at: 1 ]!
- "Answer a SortedCollection of all class names."
- | names |
- cachedClassNames == nil ifTrue:
- [names := OrderedCollection new: self size.
- self keysAndValuesDo:[:key :value|
- "The key == value name test below addresses two separate issues:
- 1) Obsolete classes, where key = #Foo and value name = 'AnObsoleteFoo'
- 2) Aliases, i.e., Smalltalk at: #OtherName put: aClass
- "
- (value isInMemory and: [(value isKindOf: Class) and: [key == value name]])
- ifTrue: [names add: key]].
- cachedClassNames := names asSortedCollection].
- ^ cachedClassNames!

Item was added:
+ ----- Method: SystemDictionary>>fillCaches (in category 'classes and traits') -----
+ fillCaches
+ "Fill cachedClassNames and cachedNonClassNames. Return an array with the calculated values."
+
+ | classNames nonClassNames |
+ classNames := OrderedCollection new: self size.
+ nonClassNames := OrderedCollection new.
+ self keysAndValuesDo: [ :key :value |
+ value isInMemory ifTrue: [
+ "The key == value name test below addresses two separate issues:
+ 1) Obsolete classes, where key = #Foo and value name = 'AnObsoleteFoo'
+ 2) Aliases, i.e., Smalltalk at: #OtherName put: aClass"
+ ((value isKindOf: Class) and: [ key == value name ])
+ ifTrue: [ classNames add: key ]
+ ifFalse: [ nonClassNames add: key ] ] ].
+ classNames sort.
+ cachedNonClassNames := nonClassNames sort.
+ cachedClassNames := classNames.
+ ^{ classNames. nonClassNames }!

Item was changed:
  ----- Method: SystemDictionary>>flushClassNameCache (in category 'classes and traits') -----
  flushClassNameCache
  "Smalltalk flushClassNameCache"
+ "Force recomputation of the cached list of class names and non-class names."
- "Force recomputation of the cached list of class names."
 
+ cachedClassNames := cachedNonClassNames := nil!
- cachedClassNames := nil!

Item was added:
+ ----- Method: SystemDictionary>>hasBindingThatBeginsWith: (in category 'as yet unclassified') -----
+ hasBindingThatBeginsWith: aString
+ "Use the cached class and non-class names for better performance."
+
+ | name searchBlock |
+ searchBlock := [ :element |
+ (element beginsWith: aString)
+ ifTrue: [ 0 ]
+ ifFalse: [
+ aString < element
+ ifTrue: [ -1 ]
+ ifFalse: [ 1 ] ] ].
+ name := self classNames
+ findBinary: searchBlock
+ ifNone: nil.
+ name ifNotNil: [ ^true ].
+ name := self nonClassNames
+ findBinary: searchBlock
+ ifNone: nil.
+ ^name notNil!

Item was added:
+ ----- Method: SystemDictionary>>nonClassNames (in category 'classes and traits') -----
+ nonClassNames
+ "Answer a sorted collection of all non-class names. Use the return value of #fillCaches to avoid concurrency issues."
+
+ ^cachedNonClassNames ifNil: [ self fillCaches at: 2 ]!