Skip to content

Commit

Permalink
Add early-out to ecs_set when there are no observers or hooks registered
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Aug 31, 2022
1 parent 383b26d commit d4f681b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 40 deletions.
33 changes: 13 additions & 20 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5384,19 +5384,6 @@ void* get_base_component(
return NULL;
}

static
const ecs_type_info_t *get_c_info(
ecs_world_t *world,
ecs_entity_t component)
{
ecs_entity_t real_id = ecs_get_typeid(world, component);
if (real_id) {
return flecs_type_info_get(world, real_id);
} else {
return NULL;
}
}

/* Utilities for creating a diff struct on the fly between two arbitrary tables.
* This is temporary code that will eventually be replaced by a cache that
* stores the diff between two archetypes. */
Expand Down Expand Up @@ -8430,10 +8417,10 @@ void flecs_copy_ptr_w_id(

ecs_record_t *r = flecs_entities_ensure(world, entity);
flecs_component_ptr_t dst = flecs_get_mut(world, entity, id, r);
const ecs_type_info_t *ti = dst.ti;
ecs_check(dst.ptr != NULL, ECS_INVALID_PARAMETER, NULL);

if (ptr) {
const ecs_type_info_t *ti = dst.ti;
ecs_copy_t copy = ti->hooks.copy;
if (copy) {
copy(dst.ptr, ptr, 1, ti);
Expand All @@ -8446,9 +8433,12 @@ void flecs_copy_ptr_w_id(

flecs_table_mark_dirty(world, r->table, id);

ecs_type_t ids = { .array = &id, .count = 1 };
flecs_notify_on_set(
world, r->table, ECS_RECORD_TO_ROW(r->row), 1, &ids, true);
ecs_table_t *table = r->table;
if (table->flags & EcsTableHasOnSet || ti->hooks.on_set) {
ecs_type_t ids = { .array = &id, .count = 1 };
flecs_notify_on_set(
world, table, ECS_RECORD_TO_ROW(r->row), 1, &ids, true);
}

flecs_defer_end(world, stage);
error:
Expand Down Expand Up @@ -8493,9 +8483,12 @@ void flecs_move_ptr_w_id(
flecs_table_mark_dirty(world, r->table, id);

if (flecs_notify) {
ecs_type_t ids = { .array = &id, .count = 1 };
flecs_notify_on_set(
world, r->table, ECS_RECORD_TO_ROW(r->row), 1, &ids, true);
ecs_table_t *table = r->table;
if (table->flags & EcsTableHasOnSet || ti->hooks.on_set) {
ecs_type_t ids = { .array = &id, .count = 1 };
flecs_notify_on_set(
world, table, ECS_RECORD_TO_ROW(r->row), 1, &ids, true);
}
}

flecs_defer_end(world, stage);
Expand Down
33 changes: 13 additions & 20 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,6 @@ void* get_base_component(
return NULL;
}

static
const ecs_type_info_t *get_c_info(
ecs_world_t *world,
ecs_entity_t component)
{
ecs_entity_t real_id = ecs_get_typeid(world, component);
if (real_id) {
return flecs_type_info_get(world, real_id);
} else {
return NULL;
}
}

/* Utilities for creating a diff struct on the fly between two arbitrary tables.
* This is temporary code that will eventually be replaced by a cache that
* stores the diff between two archetypes. */
Expand Down Expand Up @@ -3200,10 +3187,10 @@ void flecs_copy_ptr_w_id(

ecs_record_t *r = flecs_entities_ensure(world, entity);
flecs_component_ptr_t dst = flecs_get_mut(world, entity, id, r);
const ecs_type_info_t *ti = dst.ti;
ecs_check(dst.ptr != NULL, ECS_INVALID_PARAMETER, NULL);

if (ptr) {
const ecs_type_info_t *ti = dst.ti;
ecs_copy_t copy = ti->hooks.copy;
if (copy) {
copy(dst.ptr, ptr, 1, ti);
Expand All @@ -3216,9 +3203,12 @@ void flecs_copy_ptr_w_id(

flecs_table_mark_dirty(world, r->table, id);

ecs_type_t ids = { .array = &id, .count = 1 };
flecs_notify_on_set(
world, r->table, ECS_RECORD_TO_ROW(r->row), 1, &ids, true);
ecs_table_t *table = r->table;
if (table->flags & EcsTableHasOnSet || ti->hooks.on_set) {
ecs_type_t ids = { .array = &id, .count = 1 };
flecs_notify_on_set(
world, table, ECS_RECORD_TO_ROW(r->row), 1, &ids, true);
}

flecs_defer_end(world, stage);
error:
Expand Down Expand Up @@ -3263,9 +3253,12 @@ void flecs_move_ptr_w_id(
flecs_table_mark_dirty(world, r->table, id);

if (flecs_notify) {
ecs_type_t ids = { .array = &id, .count = 1 };
flecs_notify_on_set(
world, r->table, ECS_RECORD_TO_ROW(r->row), 1, &ids, true);
ecs_table_t *table = r->table;
if (table->flags & EcsTableHasOnSet || ti->hooks.on_set) {
ecs_type_t ids = { .array = &id, .count = 1 };
flecs_notify_on_set(
world, table, ECS_RECORD_TO_ROW(r->row), 1, &ids, true);
}
}

flecs_defer_end(world, stage);
Expand Down

0 comments on commit d4f681b

Please sign in to comment.