aboutsummaryrefslogtreecommitdiff
path: root/src/docs_writer.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-05-22 15:23:24 +0100
committergingerBill <bill@gingerbill.org>2023-05-22 15:23:24 +0100
commitb76fc585431e7d10338bb175334945294b4a57ac (patch)
treeb7713de0cd6d41b5967ee8cd76bdf6eb3c43dacf /src/docs_writer.cpp
parent9fc9981a9e94db9819bb6a7e6f94fc7c72c5e5b8 (diff)
Inline `are_types_identical_unique_tuples` to improve `odin_doc_type` performance
Diffstat (limited to 'src/docs_writer.cpp')
-rw-r--r--src/docs_writer.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp
index 7488e955a..3c27552f5 100644
--- a/src/docs_writer.cpp
+++ b/src/docs_writer.cpp
@@ -471,6 +471,8 @@ gb_internal OdinDocArray<OdinDocEntityIndex> odin_doc_add_entity_as_slice(OdinDo
return odin_write_item_as_slice(w, index);
}
+
+
gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
if (type == nullptr) {
return 0;
@@ -481,12 +483,41 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
}
for (auto const &entry : w->type_cache) {
// NOTE(bill): THIS IS SLOW
- Type *other = entry.key;
- if (are_types_identical_unique_tuples(type, other)) {
- OdinDocTypeIndex index = entry.value;
- map_set(&w->type_cache, type, index);
- return index;
+ Type *x = type;
+ Type *y = entry.key;
+
+ if (x == y) {
+ goto do_set;
+ }
+
+ if (!x | !y) {
+ continue;
+ }
+
+ if (x->kind == Type_Named) {
+ Entity *e = x->Named.type_name;
+ if (e->TypeName.is_type_alias) {
+ x = x->Named.base;
+ }
}
+ if (y->kind == Type_Named) {
+ Entity *e = y->Named.type_name;
+ if (e->TypeName.is_type_alias) {
+ y = y->Named.base;
+ }
+ }
+ if (x->kind != y->kind) {
+ continue;
+ }
+
+ if (!are_types_identical_internal(x, y, true)) {
+ continue;
+ }
+
+ do_set:
+ OdinDocTypeIndex index = entry.value;
+ map_set(&w->type_cache, type, index);
+ return index;
}