[Cuis-dev] allSuperclasses --- ~45% faster

Andres Valloud ten at smallinteger.com
Fri Aug 23 15:43:06 PDT 2019


| allClasses |
Smalltalk garbageCollect.
allClasses := Object withAllSubclasses.
Time millisecondsToRun: [1000 timesRepeat: [allClasses do: [:each | each 
allSuperclasses]]] 831

| allClasses |
Smalltalk garbageCollect.
allClasses := Object withAllSubclasses.
Time millisecondsToRun: [1000 timesRepeat: [allClasses do: [:each | each 
allSuperclassesFaster]]] 569

831 / 569.0 => 1.460456942003515
-------------- next part --------------
'From Cuis 4.2 of 25 July 2013 [latest update: #2595] on 23 August 2019 at 3:41:05.87914 pm'!

!Behavior methodsFor: 'accessing class hierarchy' stamp: 'sqr 8/23/2019 15:41'!
allSuperclasses
	"Answer an OrderedCollection of the receiver's and the receiver's  
	ancestor's superclasses. The first element is the receiver's immediate  
	superclass, followed by its superclass; the last element is Object."

	| answer pivot |
	answer := OrderedCollection new.
	pivot := superclass.
	[pivot == nil] whileFalse:
		[
			answer add: pivot.
			pivot := pivot superclass
		].
	^answer! !


More information about the Cuis-dev mailing list