mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-12 14:23:33 +00:00
Use macro instead of a C++ iterator - for speed
C++ iterators are bad.
This commit is contained in:
@@ -1915,7 +1915,7 @@ gb_internal void add_deps_from_child_to_parent(DeclInfo *decl) {
|
||||
rw_mutex_shared_lock(&decl->deps_mutex);
|
||||
rw_mutex_lock(&decl->parent->deps_mutex);
|
||||
|
||||
for (Entity *e : decl->deps) {
|
||||
FOR_PTR_SET(e, decl->deps) {
|
||||
ptr_set_add(&decl->parent->deps, e);
|
||||
}
|
||||
|
||||
|
||||
@@ -6028,7 +6028,7 @@ gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize
|
||||
}
|
||||
rw_mutex_shared_lock(&decl->deps_mutex);
|
||||
rw_mutex_lock(&c->decl->deps_mutex);
|
||||
for (Entity *dep : decl->deps) {
|
||||
FOR_PTR_SET(dep, decl->deps) {
|
||||
ptr_set_add(&c->decl->deps, dep);
|
||||
}
|
||||
rw_mutex_unlock(&c->decl->deps_mutex);
|
||||
|
||||
@@ -2584,7 +2584,7 @@ gb_internal void add_dependency_to_set(Checker *c, Entity *entity) {
|
||||
for (TypeInfoPair const tt : decl->type_info_deps) {
|
||||
add_min_dep_type_info(c, tt.type);
|
||||
}
|
||||
for (Entity *e : decl->deps) {
|
||||
FOR_PTR_SET(e, decl->deps) {
|
||||
switch (e->kind) {
|
||||
case Entity_Procedure:
|
||||
if (e->Procedure.is_foreign) {
|
||||
@@ -2611,7 +2611,7 @@ gb_internal void add_dependency_to_set(Checker *c, Entity *entity) {
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity *e : decl->deps) {
|
||||
FOR_PTR_SET(e, decl->deps) {
|
||||
add_dependency_to_set(c, e);
|
||||
}
|
||||
|
||||
@@ -2643,7 +2643,7 @@ gb_internal WORKER_TASK_PROC(add_dependency_to_set_worker) {
|
||||
add_min_dep_type_info(c, tt.type);
|
||||
}
|
||||
|
||||
for (Entity *e : decl->deps) {
|
||||
FOR_PTR_SET(e, decl->deps) {
|
||||
switch (e->kind) {
|
||||
case Entity_Procedure:
|
||||
if (e->Procedure.is_foreign) {
|
||||
@@ -2670,7 +2670,7 @@ gb_internal WORKER_TASK_PROC(add_dependency_to_set_worker) {
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity *e : decl->deps) {
|
||||
FOR_PTR_SET(e, decl->deps) {
|
||||
add_dependency_to_set_threaded(c, e);
|
||||
}
|
||||
|
||||
@@ -3047,9 +3047,7 @@ gb_internal Array<EntityGraphNode *> generate_entity_dependency_graph(CheckerInf
|
||||
DeclInfo *decl = decl_info_of_entity(e);
|
||||
GB_ASSERT(decl != nullptr);
|
||||
|
||||
FOR_PTR_SET(i_dep, decl->deps) {
|
||||
Entity *dep = decl->deps.keys[i_dep];
|
||||
|
||||
FOR_PTR_SET(dep, decl->deps) {
|
||||
if (dep->flags & EntityFlag_Field) {
|
||||
continue;
|
||||
}
|
||||
@@ -3080,21 +3078,14 @@ gb_internal Array<EntityGraphNode *> generate_entity_dependency_graph(CheckerInf
|
||||
|
||||
// Connect each pred 'p' of 'n' with each succ 's' and from
|
||||
// the procedure node
|
||||
FOR_PTR_SET(i_p, n->pred) {
|
||||
EntityGraphNode *p = n->pred.keys[i_p];
|
||||
|
||||
FOR_PTR_SET(p, n->pred) {
|
||||
// Ignore self-cycles
|
||||
if (p == n) {
|
||||
continue;
|
||||
}
|
||||
// Each succ 's' of 'n' becomes a succ of 'p', and
|
||||
// each pred 'p' of 'n' becomes a pred of 's'
|
||||
FOR_PTR_SET(i_s, n->succ) {
|
||||
EntityGraphNode *s = n->succ.keys[i_s];
|
||||
if (s == nullptr || s == cast(EntityGraphNode *)PtrSet<EntityGraphNode *>::TOMBSTONE) {
|
||||
// NOTE(bill): This is inlined to improve development build performance
|
||||
continue;
|
||||
}
|
||||
FOR_PTR_SET(s, n->succ) {
|
||||
// Ignore self-cycles
|
||||
if (s == n) {
|
||||
continue;
|
||||
@@ -5859,7 +5850,7 @@ gb_internal void check_import_entities(Checker *c) {
|
||||
}
|
||||
}
|
||||
|
||||
for (ImportGraphNode *p : n->pred) {
|
||||
FOR_PTR_SET(p, n->pred) {
|
||||
p->dep_count = gb_max(p->dep_count-1, 0);
|
||||
priority_queue_fix(&pq, p->index);
|
||||
}
|
||||
@@ -5976,7 +5967,8 @@ gb_internal bool find_entity_path_tuple(Type *tuple, Entity *end, gbAllocator al
|
||||
if (var_decl == nullptr) {
|
||||
continue;
|
||||
}
|
||||
for (Entity *dep : var_decl->deps) {
|
||||
|
||||
FOR_PTR_SET(dep, var_decl->deps) {
|
||||
if (dep == end) {
|
||||
auto path = array_make<Entity *>(allocator);
|
||||
array_add(&path, dep);
|
||||
@@ -6026,7 +6018,7 @@ gb_internal Array<Entity *> find_entity_path(Entity *start, Entity *end, gbAlloc
|
||||
return path;
|
||||
}
|
||||
} else {
|
||||
for (Entity *dep : decl->deps) {
|
||||
FOR_PTR_SET(dep, decl->deps) {
|
||||
if (dep == end) {
|
||||
auto path = array_make<Entity *>(allocator);
|
||||
array_add(&path, dep);
|
||||
@@ -6080,7 +6072,7 @@ gb_internal void calculate_global_init_order(Checker *c) {
|
||||
}
|
||||
}
|
||||
|
||||
for (EntityGraphNode *p : n->pred) {
|
||||
FOR_PTR_SET(p, n->pred) {
|
||||
p->dep_count -= 1;
|
||||
p->dep_count = gb_max(p->dep_count, 0);
|
||||
priority_queue_fix(&pq, p->index);
|
||||
@@ -6273,7 +6265,7 @@ gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *u
|
||||
add_untyped_expressions(&c->info, ctx.untyped);
|
||||
|
||||
rw_mutex_shared_lock(&ctx.decl->deps_mutex);
|
||||
for (Entity *dep : ctx.decl->deps) {
|
||||
FOR_PTR_SET(dep, ctx.decl->deps) {
|
||||
if (dep && dep->kind == Entity_Procedure &&
|
||||
(dep->flags & EntityFlag_ProcBodyChecked) == 0) {
|
||||
check_procedure_later_from_entity(c, dep, NULL);
|
||||
@@ -7346,7 +7338,7 @@ gb_internal void check_parsed_files(Checker *c) {
|
||||
DeclInfo *decl = e->decl_info;
|
||||
ast_node(pl, ProcLit, decl->proc_lit);
|
||||
if (pl->inlining == ProcInlining_inline) {
|
||||
for (Entity *dep : decl->deps) {
|
||||
FOR_PTR_SET(dep, decl->deps) {
|
||||
if (dep == e) {
|
||||
error(e->token, "Cannot inline recursive procedure '%.*s'", LIT(e->token.string));
|
||||
break;
|
||||
|
||||
@@ -16,6 +16,8 @@ template <typename T> gb_internal bool ptr_set_exists (PtrSet<T> *s, T ptr);
|
||||
template <typename T> gb_internal void ptr_set_remove (PtrSet<T> *s, T ptr);
|
||||
template <typename T> gb_internal void ptr_set_clear (PtrSet<T> *s);
|
||||
|
||||
#define FOR_PTR_SET(element, set_) for (auto *it = &(set_).keys[0], element = it ? *it : nullptr; (set_).keys != nullptr && it < &(set_).keys[(set_).capacity]; it++) if (element = *it, (*it != nullptr && *it != cast(void *)~(uintptr)(0ull)))
|
||||
|
||||
gb_internal gbAllocator ptr_set_allocator(void) {
|
||||
return heap_allocator();
|
||||
}
|
||||
@@ -83,7 +85,7 @@ gb_internal gb_inline void ptr_set_grow(PtrSet<T> *old_set) {
|
||||
PtrSet<T> new_set = {};
|
||||
ptr_set_init(&new_set, gb_max(old_set->capacity<<1, 16));
|
||||
|
||||
for (T ptr : *old_set) {
|
||||
FOR_PTR_SET(ptr, *old_set) {
|
||||
bool was_new = ptr_set_update(&new_set, ptr);
|
||||
GB_ASSERT(!was_new);
|
||||
}
|
||||
@@ -195,7 +197,7 @@ gb_internal gb_inline void ptr_set_clear(PtrSet<T> *s) {
|
||||
gb_zero_size(s->keys, s->capacity*gb_size_of(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
/*template <typename T>
|
||||
struct PtrSetIterator {
|
||||
PtrSet<T> *set;
|
||||
usize index;
|
||||
@@ -239,7 +241,6 @@ gb_internal PtrSetIterator<T> begin(PtrSet<T> &set) noexcept {
|
||||
template <typename T>
|
||||
gb_internal PtrSetIterator<T> end(PtrSet<T> &set) noexcept {
|
||||
return PtrSetIterator<T>{&set, set.capacity};
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
#define FOR_PTR_SET(index_, set_) for (usize index_ = 0; index_ < (set_).capacity; index_++) if ((set_).keys[index_] != nullptr && (set_).keys[index_] != cast(void *)~(uintptr)(0ull))
|
||||
Reference in New Issue
Block a user