Issue 3431 in pharo: Faster traitNames

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

Issue 3431 in pharo: Faster traitNames

pharo
Status: FixedWaitingToBePharoed
Owner: stephane.ducasse
Labels: Milestone-1.3

New issue 3431 by stephane.ducasse: Faster traitNames
http://code.google.com/p/pharo/issues/detail?id=3431

Name: System-ul.398
Author: ul
Time: 8 December 2010, 9:21:23.04 pm
UUID: 8e147d50-061f-6741-8eb3-b8f69182a3de
Ancestors: System-ul.397

- fix: SystemDictionary >> #traitNames returns a sorted collection. It also  
uses the cached nonClassNames which is faster.
- added SystemDictionary >> #classAndTraitNames which returns a sorted  
collection of all class and trait names

=============== Diff against System-ul.397 ===============

Item was added:
+ ----- Method: SystemDictionary>>classAndTraitNames (in category 'classes  
and traits') -----
+ classAndTraitNames
+       "Answer a sorted collection of all class and trait (not including  
class-traits) names. The performance of this algorithm is O(n) if the  
classNames are already cached, otherwise O(n*log(n)) where n is self size."
+
+       | classNames traitNames result temporary |
+       classNames := self classNames.
+       traitNames := self traitNames.
+       temporary := Array new: classNames size + traitNames size.
+       result := temporary shallowCopy.
+       temporary
+               replaceFrom: 1
+               to: classNames size
+               with: classNames
+               startingAt: 1;
+               replaceFrom: classNames size + 1
+               to: temporary size
+               with: traitNames
+               startingAt: 1;
+               mergeFirst: 1
+               middle: classNames size
+               last: temporary size
+               into: result
+               by: nil.
+       ^result!

Item was changed:
  ----- Method: SystemDictionary>>traitNames (in category 'classes and  
traits') -----
  traitNames
+       "Answer a sorted collection of all traits (not including  
class-traits) names."
+
+       ^self nonClassNames select: [ :name |
+               (name beginsWith: 'AnObsolete') not and: [
+                       self
+                               at: name
+                               ifPresent: [ :global | global isInMemory  
and: [ global isTrait ] ]
+                               ifAbsent: [ false ] ] ]!
-       "Answer a SortedCollection of all traits (not including  
class-traits) names."
-       | names |
-       names := OrderedCollection new.
-       self do:
-               [:cl | (cl isInMemory
-                       and: [(cl isTrait)
-                       and: [(cl name beginsWith: 'AnObsolete') not]])
-                               ifTrue: [names add: cl name]].
-       ^ names!



Reply | Threaded
Open this post in threaded view
|

Re: Issue 3431 in pharo: Faster traitNames

pharo
Updates:
        Labels: Difficulty-Easy

Comment #1 on issue 3431 by stephane.ducasse: Faster traitNames
http://code.google.com/p/pharo/issues/detail?id=3431

(No comment was entered for this change.)