From 5b06934e85c36d49a805292d5b3629acc02e84de Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 4 Jan 2026 18:58:04 +0000 Subject: [PATCH] mie: ctx: add int, string, and index value caches --- mie/ctx.c | 24 ++++++++++++++++++++++++ mie/include/mie/ctx.h | 20 +++++++++++--------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/mie/ctx.c b/mie/ctx.c index 41ece63..ced1cc8 100644 --- a/mie/ctx.c +++ b/mie/ctx.c @@ -1,8 +1,12 @@ +#include #include #include #include #include +#include +#include #include +#include #include #include #include @@ -312,6 +316,10 @@ struct mie_ctx *mie_ctx_create(void) mie_id types_ns = TYPE_NS_ID; mie_id_map_init(&out->ctx_types, &types_ns); + out->ctx_ints = mie_int_cache_create(); + out->ctx_indices = mie_index_cache_create(); + out->ctx_strings = mie_string_cache_create(); + return out; } @@ -439,3 +447,19 @@ struct mie_type *mie_ctx_get_type( return type; } + +struct mie_value *mie_ctx_get_int(struct mie_ctx *ctx, long long val, size_t nr_bits) +{ + return (struct mie_value *)mie_int_cache_get( + ctx->ctx_ints, ctx, val, nr_bits); +} + +struct mie_value *mie_ctx_get_string(struct mie_ctx *ctx, const char *s) +{ + return (struct mie_value *)mie_string_cache_get(ctx->ctx_strings, ctx, s); +} + +struct mie_value *mie_ctx_get_index(struct mie_ctx *ctx, size_t val) +{ + return (struct mie_value *)mie_index_cache_get(ctx->ctx_indices, ctx, val); +} diff --git a/mie/include/mie/ctx.h b/mie/include/mie/ctx.h index 5ba9b23..be8ea7c 100644 --- a/mie/include/mie/ctx.h +++ b/mie/include/mie/ctx.h @@ -6,6 +6,10 @@ #include struct mie_op; +struct mie_int_cache; +struct mie_index_cache; +struct mie_string_cache; +; struct mie_ctx { #if 0 @@ -17,9 +21,10 @@ struct mie_ctx { #endif struct mie_id_map ctx_dialects; struct mie_id_map ctx_types; - b_btree ctx_int_cache; - b_btree ctx_float_cache; - b_btree ctx_index_cache; + + struct mie_int_cache *ctx_ints; + struct mie_index_cache *ctx_indices; + struct mie_string_cache *ctx_strings; }; MIE_API struct mie_ctx *mie_ctx_create(void); @@ -34,15 +39,12 @@ MIE_API struct mie_dialect_type *mie_ctx_get_dialect_type( MIE_API struct mie_type *mie_ctx_get_type( struct mie_ctx *ctx, const char *dialect_name, const char *type_name); -MIE_API struct mie_type *mie_ctx_get_int_type( - struct mie_ctx *ctx, unsigned int nr_bits); -MIE_API struct mie_type *mie_ctx_get_float_type( - struct mie_ctx *ctx, unsigned int nr_bits); MIE_API struct mie_value *mie_ctx_get_null(struct mie_ctx *ctx); MIE_API struct mie_value *mie_ctx_get_int( - struct mie_ctx *ctx, long long val, unsigned int nr_bits); + struct mie_ctx *ctx, long long val, size_t nr_bits); MIE_API struct mie_value *mie_ctx_get_float( - struct mie_ctx *ctx, double val, unsigned int nr_bits); + struct mie_ctx *ctx, double val, size_t nr_bits); +MIE_API struct mie_value *mie_ctx_get_string(struct mie_ctx *ctx, const char *s); MIE_API struct mie_value *mie_ctx_get_index(struct mie_ctx *ctx, size_t val); #endif