mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-18 20:40:28 +00:00
Use *_set_update where possible
This commit is contained in:
@@ -3126,13 +3126,11 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
}
|
||||
|
||||
|
||||
if (string_set_exists(&name_set, name)) {
|
||||
if (string_set_update(&name_set, name)) {
|
||||
error(op.expr, "Field argument name '%.*s' already exists", LIT(name));
|
||||
} else {
|
||||
array_add(&types, arg_type->Slice.elem);
|
||||
array_add(&names, name);
|
||||
|
||||
string_set_add(&name_set, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1237,7 +1237,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_
|
||||
GB_PANIC("Unknown type to type switch statement");
|
||||
}
|
||||
|
||||
if (type_ptr_set_exists(&seen, y.type)) {
|
||||
if (type_ptr_set_update(&seen, y.type)) {
|
||||
TokenPos pos = cc->token.pos;
|
||||
gbString expr_str = expr_to_string(y.expr);
|
||||
error(y.expr,
|
||||
@@ -1248,7 +1248,6 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_
|
||||
gb_string_free(expr_str);
|
||||
break;
|
||||
}
|
||||
ptr_set_add(&seen, y.type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3414,11 +3414,9 @@ gb_internal void check_decl_attributes(CheckerContext *c, Array<Ast *> const &at
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string_set_exists(&set, name)) {
|
||||
if (string_set_update(&set, name)) {
|
||||
error(elem, "Previous declaration of '%.*s'", LIT(name));
|
||||
continue;
|
||||
} else {
|
||||
string_set_add(&set, name);
|
||||
}
|
||||
|
||||
if (!proc(c, elem, name, value, ac)) {
|
||||
@@ -4969,10 +4967,9 @@ gb_internal Array<Entity *> find_entity_path(Entity *start, Entity *end, PtrSet<
|
||||
|
||||
Array<Entity *> empty_path = {};
|
||||
|
||||
if (ptr_set_exists(visited, start)) {
|
||||
if (ptr_set_update(visited, start)) {
|
||||
return empty_path;
|
||||
}
|
||||
ptr_set_add(visited, start);
|
||||
|
||||
DeclInfo *decl = start->decl_info;
|
||||
if (decl) {
|
||||
|
||||
@@ -4967,10 +4967,9 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin
|
||||
String const FILE_EXT = str_lit(".odin");
|
||||
|
||||
MUTEX_GUARD_BLOCK(&p->import_mutex) {
|
||||
if (string_set_exists(&p->imported_files, path)) {
|
||||
if (string_set_update(&p->imported_files, path)) {
|
||||
return nullptr;
|
||||
}
|
||||
string_set_add(&p->imported_files, path);
|
||||
}
|
||||
|
||||
AstPackage *pkg = gb_alloc_item(permanent_allocator(), AstPackage);
|
||||
|
||||
@@ -10,18 +10,18 @@ struct StringSet {
|
||||
};
|
||||
|
||||
|
||||
void string_set_init (StringSet *s, gbAllocator a, isize capacity = 16);
|
||||
void string_set_destroy(StringSet *s);
|
||||
void string_set_add (StringSet *s, String const &str);
|
||||
bool string_set_update (StringSet *s, String const &str); // returns true if it previously existed
|
||||
bool string_set_exists (StringSet *s, String const &str);
|
||||
void string_set_remove (StringSet *s, String const &str);
|
||||
void string_set_clear (StringSet *s);
|
||||
void string_set_grow (StringSet *s);
|
||||
void string_set_rehash (StringSet *s, isize new_count);
|
||||
gb_internal void string_set_init (StringSet *s, gbAllocator a, isize capacity = 16);
|
||||
gb_internal void string_set_destroy(StringSet *s);
|
||||
gb_internal void string_set_add (StringSet *s, String const &str);
|
||||
gb_internal bool string_set_update (StringSet *s, String const &str); // returns true if it previously existed
|
||||
gb_internal bool string_set_exists (StringSet *s, String const &str);
|
||||
gb_internal void string_set_remove (StringSet *s, String const &str);
|
||||
gb_internal void string_set_clear (StringSet *s);
|
||||
gb_internal void string_set_grow (StringSet *s);
|
||||
gb_internal void string_set_rehash (StringSet *s, isize new_count);
|
||||
|
||||
|
||||
gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) {
|
||||
gb_internal gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) {
|
||||
capacity = next_pow2_isize(gb_max(16, capacity));
|
||||
|
||||
slice_init(&s->hashes, a, capacity);
|
||||
@@ -31,7 +31,7 @@ gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) {
|
||||
}
|
||||
}
|
||||
|
||||
gb_inline void string_set_destroy(StringSet *s) {
|
||||
gb_internal gb_inline void string_set_destroy(StringSet *s) {
|
||||
slice_free(&s->hashes, s->entries.allocator);
|
||||
array_free(&s->entries);
|
||||
}
|
||||
@@ -82,13 +82,13 @@ gb_internal b32 string_set__full(StringSet *s) {
|
||||
return 0.75f * s->hashes.count <= s->entries.count;
|
||||
}
|
||||
|
||||
gb_inline void string_set_grow(StringSet *s) {
|
||||
gb_internal gb_inline void string_set_grow(StringSet *s) {
|
||||
isize new_count = gb_max(s->hashes.count<<1, 16);
|
||||
string_set_rehash(s, new_count);
|
||||
}
|
||||
|
||||
|
||||
void string_set_reset_entries(StringSet *s) {
|
||||
gb_internal void string_set_reset_entries(StringSet *s) {
|
||||
for (isize i = 0; i < s->hashes.count; i++) {
|
||||
s->hashes.data[i] = MAP_SENTINEL;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ void string_set_reset_entries(StringSet *s) {
|
||||
}
|
||||
}
|
||||
|
||||
void string_set_reserve(StringSet *s, isize cap) {
|
||||
gb_internal void string_set_reserve(StringSet *s, isize cap) {
|
||||
array_reserve(&s->entries, cap);
|
||||
if (s->entries.count*2 < s->hashes.count) {
|
||||
return;
|
||||
@@ -115,7 +115,7 @@ void string_set_reserve(StringSet *s, isize cap) {
|
||||
}
|
||||
|
||||
|
||||
void string_set_rehash(StringSet *s, isize new_count) {
|
||||
gb_internal void string_set_rehash(StringSet *s, isize new_count) {
|
||||
string_set_reserve(s, new_count);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ gb_inline bool string_set_exists(StringSet *s, String const &str) {
|
||||
return index != MAP_SENTINEL;
|
||||
}
|
||||
|
||||
void string_set_add(StringSet *s, String const &str) {
|
||||
gb_internal void string_set_add(StringSet *s, String const &str) {
|
||||
MapIndex index;
|
||||
MapFindResult fr;
|
||||
StringHashKey key = string_hash_string(str);
|
||||
@@ -150,7 +150,7 @@ void string_set_add(StringSet *s, String const &str) {
|
||||
}
|
||||
}
|
||||
|
||||
bool string_set_update(StringSet *s, String const &str) {
|
||||
gb_internal bool string_set_update(StringSet *s, String const &str) {
|
||||
bool exists = false;
|
||||
MapIndex index;
|
||||
MapFindResult fr;
|
||||
@@ -179,7 +179,7 @@ bool string_set_update(StringSet *s, String const &str) {
|
||||
}
|
||||
|
||||
|
||||
void string_set__erase(StringSet *s, MapFindResult fr) {
|
||||
gb_internal void string_set__erase(StringSet *s, MapFindResult fr) {
|
||||
MapFindResult last;
|
||||
if (fr.entry_prev == MAP_SENTINEL) {
|
||||
s->hashes[fr.hash_index] = s->entries[fr.entry_index].next;
|
||||
@@ -201,7 +201,7 @@ void string_set__erase(StringSet *s, MapFindResult fr) {
|
||||
}
|
||||
}
|
||||
|
||||
void string_set_remove(StringSet *s, String const &str) {
|
||||
gb_internal void string_set_remove(StringSet *s, String const &str) {
|
||||
StringHashKey key = string_hash_string(str);
|
||||
MapFindResult fr = string_set__find(s, key);
|
||||
if (fr.entry_index != MAP_SENTINEL) {
|
||||
@@ -209,7 +209,7 @@ void string_set_remove(StringSet *s, String const &str) {
|
||||
}
|
||||
}
|
||||
|
||||
gb_inline void string_set_clear(StringSet *s) {
|
||||
gb_internal gb_inline void string_set_clear(StringSet *s) {
|
||||
array_clear(&s->entries);
|
||||
for_array(i, s->hashes) {
|
||||
s->hashes.data[i] = MAP_SENTINEL;
|
||||
@@ -218,18 +218,18 @@ gb_inline void string_set_clear(StringSet *s) {
|
||||
|
||||
|
||||
|
||||
StringSetEntry *begin(StringSet &m) {
|
||||
gb_internal StringSetEntry *begin(StringSet &m) {
|
||||
return m.entries.data;
|
||||
}
|
||||
StringSetEntry const *begin(StringSet const &m) {
|
||||
gb_internal StringSetEntry const *begin(StringSet const &m) {
|
||||
return m.entries.data;
|
||||
}
|
||||
|
||||
|
||||
StringSetEntry *end(StringSet &m) {
|
||||
gb_internal StringSetEntry *end(StringSet &m) {
|
||||
return m.entries.data + m.entries.count;
|
||||
}
|
||||
|
||||
StringSetEntry const *end(StringSet const &m) {
|
||||
gb_internal StringSetEntry const *end(StringSet const &m) {
|
||||
return m.entries.data + m.entries.count;
|
||||
}
|
||||
@@ -812,7 +812,7 @@ gb_internal void init_type_mutex(void) {
|
||||
mutex_init(&g_type_mutex);
|
||||
}
|
||||
|
||||
gb_internal bool type_ptr_set_exists(PtrSet<Type *> *s, Type *t) {
|
||||
gb_internal bool type_ptr_set_update(PtrSet<Type *> *s, Type *t) {
|
||||
if (ptr_set_exists(s, t)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user