@@ -20,9 +20,12 @@ export function runQuery<T extends QueryParameter[]>(world: World, query: Query<
2020 const entityIndex = ctx . entityIndex ;
2121
2222 // Build Entity[] from BitSet by looking up packed entities via entityIndex.
23- const entities : Entity [ ] = [ ] ;
23+ const dense = entityIndex . dense ;
24+ const sparse = entityIndex . sparse ;
25+ const entities : Entity [ ] = new Array ( query . entities . count ) ;
26+ let ei = 0 ;
2427 query . entities . forEach ( ( eid ) => {
25- entities . push ( entityIndex . dense [ entityIndex . sparse [ eid ] ] as Entity ) ;
28+ entities [ ei ++ ] = dense [ sparse [ eid ] ] as Entity ;
2629 } ) ;
2730
2831 // Clear so it can accumulate again.
@@ -227,20 +230,20 @@ export function createQuery<T extends QueryParameter[]>(world: World, parameters
227230 // Register traits if they don't exist.
228231 for ( let j = 0 ; j < traits . length ; j ++ ) {
229232 const trait = traits [ j ] ;
230- if ( ! ctx . traitData . has ( trait ) ) registerTrait ( world , trait ) ;
233+ if ( ! ctx . traitData [ trait [ $internal ] . id ] ) registerTrait ( world , trait ) ;
231234 }
232235
233236 if ( parameter . type === 'not' ) {
234- query . traitData . forbidden . push ( ...traits . map ( ( trait ) => ctx . traitData . get ( trait ) ! ) ) ;
237+ query . traitData . forbidden . push ( ...traits . map ( ( trait ) => ctx . traitData [ trait [ $internal ] . id ] ! ) ) ;
235238 }
236239
237240 if ( parameter . type === 'or' ) {
238- query . traitData . or . push ( ...traits . map ( ( trait ) => ctx . traitData . get ( trait ) ! ) ) ;
241+ query . traitData . or . push ( ...traits . map ( ( trait ) => ctx . traitData [ trait [ $internal ] . id ] ! ) ) ;
239242 }
240243
241244 if ( parameter . type . includes ( 'added' ) ) {
242245 for ( const trait of traits ) {
243- const data = ctx . traitData . get ( trait ) ! ;
246+ const data = ctx . traitData [ trait [ $internal ] . id ] ! ;
244247 query . traitData . added . push ( data ) ;
245248 query . traits . push ( trait ) ;
246249 }
@@ -257,7 +260,7 @@ export function createQuery<T extends QueryParameter[]>(world: World, parameters
257260
258261 if ( parameter . type . includes ( 'removed' ) ) {
259262 for ( const trait of traits ) {
260- const data = ctx . traitData . get ( trait ) ! ;
263+ const data = ctx . traitData [ trait [ $internal ] . id ] ! ;
261264 query . traitData . removed . push ( data ) ;
262265 query . traits . push ( trait ) ;
263266 }
@@ -275,7 +278,7 @@ export function createQuery<T extends QueryParameter[]>(world: World, parameters
275278 if ( parameter . type . includes ( 'changed' ) ) {
276279 for ( const trait of traits ) {
277280 query . changedTraits . add ( trait ) ;
278- const data = ctx . traitData . get ( trait ) ! ;
281+ const data = ctx . traitData [ trait [ $internal ] . id ] ! ;
279282 query . traitData . changed . push ( data ) ;
280283 query . traits . push ( trait ) ;
281284 query . hasChangedModifiers = true ;
@@ -292,14 +295,15 @@ export function createQuery<T extends QueryParameter[]>(world: World, parameters
292295 }
293296 } else {
294297 const trait = parameter as Trait ;
295- if ( ! ctx . traitData . has ( trait ) ) registerTrait ( world , trait ) ;
296- query . traitData . required . push ( ctx . traitData . get ( trait ) ! ) ;
298+ const tid = trait [ $internal ] . id ;
299+ if ( ! ctx . traitData [ tid ] ) registerTrait ( world , trait ) ;
300+ query . traitData . required . push ( ctx . traitData [ tid ] ! ) ;
297301 query . traits . push ( trait ) ;
298302 }
299303 }
300304
301305 // Add IsExcluded to the forbidden list.
302- query . traitData . forbidden . push ( ctx . traitData . get ( IsExcluded ) ! ) ;
306+ query . traitData . forbidden . push ( ctx . traitData [ IsExcluded [ $internal ] . id ] ! ) ;
303307
304308 query . traitData . all = [
305309 ...query . traitData . required ,
@@ -366,12 +370,12 @@ export function createQuery<T extends QueryParameter[]>(world: World, parameters
366370 ctx . queriesHashMap . set ( query . hash , query ) ;
367371
368372 // Add query to each trait instance.
369- query . traitData . all . forEach ( ( instance ) => {
370- instance . queries . add ( query ) ;
371- } ) ;
373+ for ( let i = 0 ; i < query . traitData . all . length ; i ++ ) {
374+ query . traitData . all [ i ] . queries . push ( query ) ;
375+ }
372376
373377 // Add query instance to the world's not-query store.
374- if ( query . traitData . forbidden . length > 0 ) ctx . notQueries . add ( query ) ;
378+ if ( query . traitData . forbidden . length > 0 ) ctx . notQueries . push ( query ) ;
375379
376380 // Populate the query with tracking parameters.
377381 if ( trackingParams . length > 0 ) {
0 commit comments