Skip to content

Commit

Permalink
Cache id record for (Identifier, Name) on world
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Mar 3, 2023
1 parent af35a42 commit ad57df2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
16 changes: 10 additions & 6 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ struct ecs_world_t {
ecs_id_record_t *idr_isa_wildcard;
ecs_id_record_t *idr_childof_0;
ecs_id_record_t *idr_childof_wildcard;
ecs_id_record_t *idr_identifier_name;

/* -- Mixins -- */
ecs_world_t *self;
Expand Down Expand Up @@ -55543,23 +55544,24 @@ ecs_table_t* flecs_bootstrap_component_table(
ecs_id_record_t *idr = flecs_id_record_ensure(world, EcsChildOf);
idr->flags |= EcsIdOnDeleteObjectDelete | EcsIdDontInherit |
EcsIdTraversable | EcsIdTag;

/* Initialize id records cached on world */
world->idr_childof_wildcard = flecs_id_record_ensure(world,
ecs_pair(EcsChildOf, EcsWildcard));
world->idr_childof_wildcard->flags |= EcsIdOnDeleteObjectDelete |
EcsIdDontInherit | EcsIdTraversable | EcsIdTag | EcsIdExclusive;

idr = flecs_id_record_ensure(
world, ecs_pair(ecs_id(EcsIdentifier), EcsWildcard));
idr = flecs_id_record_ensure(world, ecs_pair_t(EcsIdentifier, EcsWildcard));
idr->flags |= EcsIdDontInherit;

world->idr_identifier_name =
flecs_id_record_ensure(world, ecs_pair_t(EcsIdentifier, EcsName));
world->idr_childof_0 = flecs_id_record_ensure(world,
ecs_pair(EcsChildOf, 0));

ecs_id_t ids[] = {
ecs_id(EcsComponent),
EcsFinal,
ecs_pair(ecs_id(EcsIdentifier), EcsName),
ecs_pair(ecs_id(EcsIdentifier), EcsSymbol),
ecs_pair_t(EcsIdentifier, EcsName),
ecs_pair_t(EcsIdentifier, EcsSymbol),
ecs_pair(EcsChildOf, EcsFlecsCore),
ecs_pair(EcsOnDelete, EcsPanic)
};
Expand Down Expand Up @@ -57012,6 +57014,8 @@ ecs_id_record_t* flecs_id_record_get(
return world->idr_isa_wildcard;
} else if (id == ecs_pair(EcsChildOf, EcsWildcard)) {
return world->idr_childof_wildcard;
} else if (id == ecs_pair_t(EcsIdentifier, EcsName)) {
return world->idr_identifier_name;
}

ecs_id_t hash = flecs_id_record_hash(id);
Expand Down
1 change: 1 addition & 0 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ typedef struct ecs_allocator_t ecs_allocator_t;
#define ecs_entity_t_comb(lo, hi) ((ECS_CAST(uint64_t, hi) << 32) + ECS_CAST(uint32_t, lo))

#define ecs_pair(pred, obj) (ECS_PAIR | ecs_entity_t_comb(obj, pred))
#define ecs_pair_t(pred, obj) (ECS_PAIR | ecs_entity_t_comb(obj, ecs_id(pred)))
#define ecs_pair_first(world, pair) ecs_get_alive(world, ECS_PAIR_FIRST(pair))
#define ecs_pair_second(world, pair) ecs_get_alive(world, ECS_PAIR_SECOND(pair))
#define ecs_pair_relation ecs_pair_first
Expand Down
1 change: 1 addition & 0 deletions include/flecs/private/api_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ typedef struct ecs_allocator_t ecs_allocator_t;
#define ecs_entity_t_comb(lo, hi) ((ECS_CAST(uint64_t, hi) << 32) + ECS_CAST(uint32_t, lo))

#define ecs_pair(pred, obj) (ECS_PAIR | ecs_entity_t_comb(obj, pred))
#define ecs_pair_t(pred, obj) (ECS_PAIR | ecs_entity_t_comb(obj, ecs_id(pred)))
#define ecs_pair_first(world, pair) ecs_get_alive(world, ECS_PAIR_FIRST(pair))
#define ecs_pair_second(world, pair) ecs_get_alive(world, ECS_PAIR_SECOND(pair))
#define ecs_pair_relation ecs_pair_first
Expand Down
13 changes: 7 additions & 6 deletions src/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,23 +587,24 @@ ecs_table_t* flecs_bootstrap_component_table(
ecs_id_record_t *idr = flecs_id_record_ensure(world, EcsChildOf);
idr->flags |= EcsIdOnDeleteObjectDelete | EcsIdDontInherit |
EcsIdTraversable | EcsIdTag;

/* Initialize id records cached on world */
world->idr_childof_wildcard = flecs_id_record_ensure(world,
ecs_pair(EcsChildOf, EcsWildcard));
world->idr_childof_wildcard->flags |= EcsIdOnDeleteObjectDelete |
EcsIdDontInherit | EcsIdTraversable | EcsIdTag | EcsIdExclusive;

idr = flecs_id_record_ensure(
world, ecs_pair(ecs_id(EcsIdentifier), EcsWildcard));
idr = flecs_id_record_ensure(world, ecs_pair_t(EcsIdentifier, EcsWildcard));
idr->flags |= EcsIdDontInherit;

world->idr_identifier_name =
flecs_id_record_ensure(world, ecs_pair_t(EcsIdentifier, EcsName));
world->idr_childof_0 = flecs_id_record_ensure(world,
ecs_pair(EcsChildOf, 0));

ecs_id_t ids[] = {
ecs_id(EcsComponent),
EcsFinal,
ecs_pair(ecs_id(EcsIdentifier), EcsName),
ecs_pair(ecs_id(EcsIdentifier), EcsSymbol),
ecs_pair_t(EcsIdentifier, EcsName),
ecs_pair_t(EcsIdentifier, EcsSymbol),
ecs_pair(EcsChildOf, EcsFlecsCore),
ecs_pair(EcsOnDelete, EcsPanic)
};
Expand Down
2 changes: 2 additions & 0 deletions src/id_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ ecs_id_record_t* flecs_id_record_get(
return world->idr_isa_wildcard;
} else if (id == ecs_pair(EcsChildOf, EcsWildcard)) {
return world->idr_childof_wildcard;
} else if (id == ecs_pair_t(EcsIdentifier, EcsName)) {
return world->idr_identifier_name;
}

ecs_id_t hash = flecs_id_record_hash(id);
Expand Down
1 change: 1 addition & 0 deletions src/private_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ struct ecs_world_t {
ecs_id_record_t *idr_isa_wildcard;
ecs_id_record_t *idr_childof_0;
ecs_id_record_t *idr_childof_wildcard;
ecs_id_record_t *idr_identifier_name;

/* -- Mixins -- */
ecs_world_t *self;
Expand Down

0 comments on commit ad57df2

Please sign in to comment.