Skip to content

Commit

Permalink
Cleanup internal table APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Aug 27, 2023
1 parent 7abdf40 commit b1b4346
Show file tree
Hide file tree
Showing 12 changed files with 872 additions and 982 deletions.
917 changes: 426 additions & 491 deletions flecs.c

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,16 @@ void* ecs_vec_grow(
#define ecs_vec_grow_t(allocator, vec, T, elem_count) \
ecs_vec_grow(allocator, vec, ECS_SIZEOF(T), elem_count)

FLECS_API
void ecs_vec_merge(
struct ecs_allocator_t *allocator,
ecs_vec_t *dst,
ecs_vec_t *src,
ecs_size_t size);

#define ecs_vec_merge_t(allocator, dst, src, T) \
ecs_vec_merge(allocator, dst, src, ECS_SIZEOF(T))

FLECS_API
int32_t ecs_vec_count(
const ecs_vec_t *vec);
Expand Down
10 changes: 10 additions & 0 deletions include/flecs/private/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ void* ecs_vec_grow(
#define ecs_vec_grow_t(allocator, vec, T, elem_count) \
ecs_vec_grow(allocator, vec, ECS_SIZEOF(T), elem_count)

FLECS_API
void ecs_vec_merge(
struct ecs_allocator_t *allocator,
ecs_vec_t *dst,
ecs_vec_t *src,
ecs_size_t size);

#define ecs_vec_merge_t(allocator, dst, src, T) \
ecs_vec_merge(allocator, dst, src, ECS_SIZEOF(T))

FLECS_API
int32_t ecs_vec_count(
const ecs_vec_t *vec);
Expand Down
25 changes: 25 additions & 0 deletions src/datastructures/vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,31 @@ void* ecs_vec_grow(
return ECS_ELEM(v->array, size, count);
}

void ecs_vec_merge(
struct ecs_allocator_t *allocator,
ecs_vec_t *dst,
ecs_vec_t *src,
ecs_size_t size)
{
int32_t dst_count = dst->count;

if (!dst_count) {
ecs_vec_fini(allocator, dst, size);
*dst = *src;
src->array = NULL;
src->count = 0;
src->size = 0;
} else {
int32_t src_count = src->count;
ecs_vec_set_count(allocator, dst, size, dst_count + src_count);

void *dst_ptr = ECS_ELEM(dst->array, size, dst_count);
void *src_ptr = src->array;
ecs_os_memcpy(dst_ptr, src_ptr, size * src_count);
ecs_vec_fini(allocator, src, size);
}
}

void* ecs_vec_append(
ecs_allocator_t *allocator,
ecs_vec_t *v,
Expand Down
9 changes: 4 additions & 5 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ void flecs_commit(
ecs_world_t *world,
ecs_entity_t entity,
ecs_record_t *record,
ecs_table_t *dst_table,
ecs_table_t *dst_table,
ecs_table_diff_t *diff,
bool construct,
ecs_flags32_t evt_flags)
Expand Down Expand Up @@ -766,7 +766,7 @@ const ecs_entity_t* flecs_bulk_new(
}

ecs_data_t *data = flecs_table_data(table);
int32_t row = flecs_table_appendn(world, table, data, count, entities);
int32_t row = flecs_table_appendn(world, table, count, entities);

/* Update entity index. */
int i;
Expand Down Expand Up @@ -2260,8 +2260,7 @@ void flecs_remove_from_table(
ecs_log_pop_3();
}

flecs_table_merge(world, dst_table, table,
flecs_table_data(dst_table), flecs_table_data(table));
flecs_table_merge(world, dst_table, table);
}
}

Expand Down Expand Up @@ -3516,7 +3515,7 @@ void flecs_flatten(
ecs_table_diff_t td;
flecs_table_diff_build_noalloc(&diff, &td);
flecs_notify_on_remove(world, table, NULL, 0, count, &td.removed);
flecs_table_merge(world, dst, table, dst->data, table->data);
flecs_table_merge(world, dst, table);
flecs_notify_on_add(world, dst, NULL, dst_count, count,
&td.added, 0);
flecs_table_diff_builder_fini(world, &diff);
Expand Down
Loading

0 comments on commit b1b4346

Please sign in to comment.