Skip to content

Commit

Permalink
Use TypeSet instead of PtrSet<Type *>
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerBill committed Feb 20, 2025
1 parent 0946f6b commit 0ab3230
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/check_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,8 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_


Ast *nil_seen = nullptr;
PtrSet<Type *> seen = {};
defer (ptr_set_destroy(&seen));
TypeSet seen = {};
defer (type_set_destroy(&seen));

for (Ast *stmt : bs->stmts) {
if (stmt->kind != Ast_CaseClause) {
Expand Down Expand Up @@ -1515,7 +1515,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_update(&seen, y.type)) {
if (type_set_update(&seen, y.type)) {
TokenPos pos = cc->token.pos;
gbString expr_str = expr_to_string(y.expr);
error(y.expr,
Expand Down Expand Up @@ -1569,7 +1569,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_
auto unhandled = array_make<Type *>(temporary_allocator(), 0, variants.count);

for (Type *t : variants) {
if (!type_ptr_set_exists(&seen, t)) {
if (!type_set_exists(&seen, t)) {
array_add(&unhandled, t);
}
}
Expand Down
34 changes: 0 additions & 34 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,40 +856,6 @@ gb_internal void type_path_pop(TypePath *tp) {
#define FAILURE_SIZE 0
#define FAILURE_ALIGNMENT 0

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 (t == nullptr) {
return true;
}
if (type_ptr_set_exists(s, t)) {
return true;
}
ptr_set_add(s, t);
return false;
}

gb_internal bool type_ptr_set_exists(PtrSet<Type *> *s, Type *t) {
if (t == nullptr) {
return true;
}

if (ptr_set_exists(s, t)) {
return true;
}

// TODO(bill, 2019-10-05): This is very slow and it's probably a lot
// faster to cache types correctly
for (Type *f : *s) {
if (are_types_identical(t, f)) {
ptr_set_add(s, t);
return true;
}
}

return false;
}

gb_internal Type *base_type(Type *t) {
for (;;) {
if (t == nullptr) {
Expand Down

0 comments on commit 0ab3230

Please sign in to comment.