From 0ab323012e4fd0303a7e41587a5919c9be028561 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 20 Feb 2025 11:12:59 +0000 Subject: [PATCH] Use `TypeSet` instead of `PtrSet` --- src/check_stmt.cpp | 8 ++++---- src/types.cpp | 34 ---------------------------------- 2 files changed, 4 insertions(+), 38 deletions(-) diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 1708f7c8162..e81996566be 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1446,8 +1446,8 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_ Ast *nil_seen = nullptr; - PtrSet seen = {}; - defer (ptr_set_destroy(&seen)); + TypeSet seen = {}; + defer (type_set_destroy(&seen)); for (Ast *stmt : bs->stmts) { if (stmt->kind != Ast_CaseClause) { @@ -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, @@ -1569,7 +1569,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_ auto unhandled = array_make(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); } } diff --git a/src/types.cpp b/src/types.cpp index 15e1bcf4595..9b23fad0f1d 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -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 *s, Type *t); - -gb_internal bool type_ptr_set_update(PtrSet *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 *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) {