Skip to content

Commit

Permalink
Introduce #rawAllUsing:
Browse files Browse the repository at this point in the history
This method does the same as #allUsing: but does not return a MooseGroup that might be long to compute. Instead it returns a classic Pharo collection.

This will be useful to improve the query model
  • Loading branch information
jecisc committed Jan 19, 2024
1 parent 4e850c8 commit 901acf0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Moose-Core/MooseAbstractGroup.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ MooseAbstractGroup >> allUsing: aTrait [
{ #category : #groups }
MooseAbstractGroup >> allUsing: aTrait ofGroupClass: aGroupClass [

aTrait isTrait ifFalse: [ MooseAllUsingOnClass signal ].
^ self cacheAt: aTrait ifAbsentPut: [
aGroupClass
withAll: (self entityStorage select: [ :entity | entity class traitComposition includesTrait: aTrait ])
withDescription: 'All ' , aTrait name asLowercase asEnglishPlural ]
^ self cacheAt: aTrait ifAbsentPut: [ aGroupClass withAll: (self rawAllUsing: aTrait) withDescription: 'All ' , aTrait name asLowercase asEnglishPlural ]
]

{ #category : #groups }
Expand Down Expand Up @@ -564,9 +560,10 @@ MooseAbstractGroup >> notEmpty [
^ self entities isNotEmpty
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
MooseAbstractGroup >> numberOfEntityUsing: aTrait [
^ (self allUsing: aTrait) size

^ (self rawAllUsing: aTrait) size
]

{ #category : #accessing }
Expand Down Expand Up @@ -596,6 +593,14 @@ MooseAbstractGroup >> printOn: aStream [
aStream nextPut: $)
]

{ #category : #groups }
MooseAbstractGroup >> rawAllUsing: aTrait [
"This is an optimization of #allUsing: when we do not need to manipulate a MooseGroup as result."

aTrait isTrait ifFalse: [ MooseAllUsingOnClass signal ].
^ self entityStorage select: [ :entity | entity class traitComposition includesTrait: aTrait ]
]

{ #category : #'adding/removing' }
MooseAbstractGroup >> readStream [
^ self entities readStream
Expand Down

0 comments on commit 901acf0

Please sign in to comment.