ui/common/document.c

branch
newapi
changeset 178
7c3ff86ee9d4
parent 174
0358f1d9c506
child 187
24ce2c326d85
--- a/ui/common/document.c	Sun Apr 16 10:20:21 2023 +0200
+++ b/ui/common/document.c	Tue May 23 11:11:28 2023 +0200
@@ -32,10 +32,13 @@
 
 #include "document.h"
 
-static UcxMap *documents;
+#include <cx/hash_map.h>
+#include <cx/basic_mempool.h>
+
+static CxMap *documents;
 
 void uic_docmgr_init() {
-    documents = ucx_map_new(32);
+    documents = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32);
 }
 
 void ui_set_document(UiObject *obj, void *document) {
@@ -77,15 +80,16 @@
 }
 
 void* ui_document_new(size_t size) {
-    UcxMempool *mp = ucx_mempool_new(256);
-    UiContext *ctx = ucx_mempool_calloc(mp, 1, sizeof(UiContext));
+    CxMempool *mp = cxBasicMempoolCreate(256);
+    const CxAllocator *a = mp->allocator;
+    UiContext *ctx = cxCalloc(a, 1, sizeof(UiContext));
     ctx->attach_document = uic_context_attach_document;
     ctx->detach_document2 = uic_context_detach_document2;
-    ctx->mempool = mp;
-    ctx->vars = ucx_map_new_a(mp->allocator, 16);
+    ctx->allocator = a;
+    ctx->vars = cxHashMapCreate(a, CX_STORE_POINTERS, 16);
     
-    void *document = ucx_mempool_calloc(mp, 1, size);
-    ucx_map_put(documents, ucx_key(&document, sizeof(void*)), ctx);
+    void *document = cxCalloc(a, 1, size);
+    cxMapPut(documents, cx_hash_key(&document, sizeof(void*)), ctx);
     return document;
 }
 
@@ -95,7 +99,7 @@
 
 UiContext* ui_document_context(void *doc) {
     if(doc) {
-        return ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
+        return cxMapGet(documents, cx_hash_key(&doc, sizeof(void*)));
     } else {
         return NULL;
     }

mercurial