[ENH] Faster allSubclasses and withAllSubclasses

Andres Valloud avalloud at exobox.com
Fri May 26 00:00:05 UTC 2000


Hi.

Here are improved methods for Squeak.

    ProtoObject allSubclasses is 7.7 times faster.
    Behavior allSubclasses is 5.x times faster.

The method withAllSubclasses was refactored to use allSubclasses.

Andres.

-------------- next part --------------
'From Squeak2.8alpha of 19 January 2000 [latest update: #2158] on 25 May 2000 at 4:55:52 pm'!
"Change Set:		allSubclasses
Date:			25 May 2000
Author:			Andres Valloud

Improved two methods in
ClassDescription. Changed the
implementation from recursive
(slow) to iterative (fast).

SqR 5/25/2000 16:55"!


!ClassDescription methodsFor: 'accessing class hierarchy' stamp: 'SqR 5/25/2000 16:52'!
allSubclasses
	"Answer a Set of the receiver's and the receiver's descendent's subclasses.
	SqR 5/25/2000 16:50. Muuuuuuuuuuuuuuch faster.
		ProtoObject allSubclasses is 7.7 times faster.
		Behavior allSubclasses is 5.x times faster"

	| scan scanTop pivot |

	scan _ OrderedCollection withAll: self subclasses.
	scanTop _ 1.
	[scanTop > scan size] whileFalse:
		[
			pivot _ scan at: scanTop.
			scan addAll: pivot subclasses.
			scanTop _ scanTop + 1
		].
	^scan asSet! !

!ClassDescription methodsFor: 'accessing class hierarchy' stamp: 'SqR 5/25/2000 16:54'!
withAllSubclasses
	"Answer a Set of the receiver, the receiver's descendent's, and the 
	receiver's descendent's subclasses. SqR 5/25/2000 16:53. Much faster."

	^self allSubclasses add: self; yourself! !



More information about the Squeak-dev mailing list