mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-01 20:28:15 +00:00
Use macro instead of a C++ iterator - for speed
C++ iterators are bad.
This commit is contained in:
+1
-1
@@ -1915,7 +1915,7 @@ gb_internal void add_deps_from_child_to_parent(DeclInfo *decl) {
|
|||||||
rw_mutex_shared_lock(&decl->deps_mutex);
|
rw_mutex_shared_lock(&decl->deps_mutex);
|
||||||
rw_mutex_lock(&decl->parent->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);
|
ptr_set_add(&decl->parent->deps, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -6028,7 +6028,7 @@ gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize
|
|||||||
}
|
}
|
||||||
rw_mutex_shared_lock(&decl->deps_mutex);
|
rw_mutex_shared_lock(&decl->deps_mutex);
|
||||||
rw_mutex_lock(&c->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);
|
ptr_set_add(&c->decl->deps, dep);
|
||||||
}
|
}
|
||||||
rw_mutex_unlock(&c->decl->deps_mutex);
|
rw_mutex_unlock(&c->decl->deps_mutex);
|
||||||
|
|||||||
+14
-22
@@ -2584,7 +2584,7 @@ gb_internal void add_dependency_to_set(Checker *c, Entity *entity) {
|
|||||||
for (TypeInfoPair const tt : decl->type_info_deps) {
|
for (TypeInfoPair const tt : decl->type_info_deps) {
|
||||||
add_min_dep_type_info(c, tt.type);
|
add_min_dep_type_info(c, tt.type);
|
||||||
}
|
}
|
||||||
for (Entity *e : decl->deps) {
|
FOR_PTR_SET(e, decl->deps) {
|
||||||
switch (e->kind) {
|
switch (e->kind) {
|
||||||
case Entity_Procedure:
|
case Entity_Procedure:
|
||||||
if (e->Procedure.is_foreign) {
|
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);
|
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);
|
add_min_dep_type_info(c, tt.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entity *e : decl->deps) {
|
FOR_PTR_SET(e, decl->deps) {
|
||||||
switch (e->kind) {
|
switch (e->kind) {
|
||||||
case Entity_Procedure:
|
case Entity_Procedure:
|
||||||
if (e->Procedure.is_foreign) {
|
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);
|
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);
|
DeclInfo *decl = decl_info_of_entity(e);
|
||||||
GB_ASSERT(decl != nullptr);
|
GB_ASSERT(decl != nullptr);
|
||||||
|
|
||||||
FOR_PTR_SET(i_dep, decl->deps) {
|
FOR_PTR_SET(dep, decl->deps) {
|
||||||
Entity *dep = decl->deps.keys[i_dep];
|
|
||||||
|
|
||||||
if (dep->flags & EntityFlag_Field) {
|
if (dep->flags & EntityFlag_Field) {
|
||||||
continue;
|
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
|
// Connect each pred 'p' of 'n' with each succ 's' and from
|
||||||
// the procedure node
|
// the procedure node
|
||||||
FOR_PTR_SET(i_p, n->pred) {
|
FOR_PTR_SET(p, n->pred) {
|
||||||
EntityGraphNode *p = n->pred.keys[i_p];
|
|
||||||
|
|
||||||
// Ignore self-cycles
|
// Ignore self-cycles
|
||||||
if (p == n) {
|
if (p == n) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Each succ 's' of 'n' becomes a succ of 'p', and
|
// Each succ 's' of 'n' becomes a succ of 'p', and
|
||||||
// each pred 'p' of 'n' becomes a pred of 's'
|
// each pred 'p' of 'n' becomes a pred of 's'
|
||||||
FOR_PTR_SET(i_s, n->succ) {
|
FOR_PTR_SET(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;
|
|
||||||
}
|
|
||||||
// Ignore self-cycles
|
// Ignore self-cycles
|
||||||
if (s == n) {
|
if (s == n) {
|
||||||
continue;
|
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);
|
p->dep_count = gb_max(p->dep_count-1, 0);
|
||||||
priority_queue_fix(&pq, p->index);
|
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) {
|
if (var_decl == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (Entity *dep : var_decl->deps) {
|
|
||||||
|
FOR_PTR_SET(dep, var_decl->deps) {
|
||||||
if (dep == end) {
|
if (dep == end) {
|
||||||
auto path = array_make<Entity *>(allocator);
|
auto path = array_make<Entity *>(allocator);
|
||||||
array_add(&path, dep);
|
array_add(&path, dep);
|
||||||
@@ -6026,7 +6018,7 @@ gb_internal Array<Entity *> find_entity_path(Entity *start, Entity *end, gbAlloc
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Entity *dep : decl->deps) {
|
FOR_PTR_SET(dep, decl->deps) {
|
||||||
if (dep == end) {
|
if (dep == end) {
|
||||||
auto path = array_make<Entity *>(allocator);
|
auto path = array_make<Entity *>(allocator);
|
||||||
array_add(&path, dep);
|
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 -= 1;
|
||||||
p->dep_count = gb_max(p->dep_count, 0);
|
p->dep_count = gb_max(p->dep_count, 0);
|
||||||
priority_queue_fix(&pq, p->index);
|
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);
|
add_untyped_expressions(&c->info, ctx.untyped);
|
||||||
|
|
||||||
rw_mutex_shared_lock(&ctx.decl->deps_mutex);
|
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 &&
|
if (dep && dep->kind == Entity_Procedure &&
|
||||||
(dep->flags & EntityFlag_ProcBodyChecked) == 0) {
|
(dep->flags & EntityFlag_ProcBodyChecked) == 0) {
|
||||||
check_procedure_later_from_entity(c, dep, NULL);
|
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;
|
DeclInfo *decl = e->decl_info;
|
||||||
ast_node(pl, ProcLit, decl->proc_lit);
|
ast_node(pl, ProcLit, decl->proc_lit);
|
||||||
if (pl->inlining == ProcInlining_inline) {
|
if (pl->inlining == ProcInlining_inline) {
|
||||||
for (Entity *dep : decl->deps) {
|
FOR_PTR_SET(dep, decl->deps) {
|
||||||
if (dep == e) {
|
if (dep == e) {
|
||||||
error(e->token, "Cannot inline recursive procedure '%.*s'", LIT(e->token.string));
|
error(e->token, "Cannot inline recursive procedure '%.*s'", LIT(e->token.string));
|
||||||
break;
|
break;
|
||||||
|
|||||||
+5
-4
@@ -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_remove (PtrSet<T> *s, T ptr);
|
||||||
template <typename T> gb_internal void ptr_set_clear (PtrSet<T> *s);
|
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) {
|
gb_internal gbAllocator ptr_set_allocator(void) {
|
||||||
return heap_allocator();
|
return heap_allocator();
|
||||||
}
|
}
|
||||||
@@ -83,7 +85,7 @@ gb_internal gb_inline void ptr_set_grow(PtrSet<T> *old_set) {
|
|||||||
PtrSet<T> new_set = {};
|
PtrSet<T> new_set = {};
|
||||||
ptr_set_init(&new_set, gb_max(old_set->capacity<<1, 16));
|
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);
|
bool was_new = ptr_set_update(&new_set, ptr);
|
||||||
GB_ASSERT(!was_new);
|
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));
|
gb_zero_size(s->keys, s->capacity*gb_size_of(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
/*template <typename T>
|
||||||
struct PtrSetIterator {
|
struct PtrSetIterator {
|
||||||
PtrSet<T> *set;
|
PtrSet<T> *set;
|
||||||
usize index;
|
usize index;
|
||||||
@@ -239,7 +241,6 @@ gb_internal PtrSetIterator<T> begin(PtrSet<T> &set) noexcept {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
gb_internal PtrSetIterator<T> end(PtrSet<T> &set) noexcept {
|
gb_internal PtrSetIterator<T> end(PtrSet<T> &set) noexcept {
|
||||||
return PtrSetIterator<T>{&set, set.capacity};
|
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