misc: replace all GHashTable with kmscon_hashtable
We use a new wrapper to move all glib deps to central points so we can replace them easily. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
2707ba7336
commit
f091b2b763
@ -35,10 +35,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include "font.h"
|
||||
#include "gl.h"
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
@ -58,7 +58,7 @@ struct kmscon_font {
|
||||
FT_Face face;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
GHashTable *glyphs;
|
||||
struct kmscon_hashtable *glyphs;
|
||||
};
|
||||
|
||||
struct kmscon_glyph {
|
||||
@ -274,12 +274,11 @@ int kmscon_font_factory_load(struct kmscon_font_factory *ff,
|
||||
goto err_face;
|
||||
}
|
||||
|
||||
font->glyphs = g_hash_table_new_full(g_direct_hash, g_direct_equal,
|
||||
NULL, (GDestroyNotify) kmscon_glyph_destroy);
|
||||
if (!font->glyphs) {
|
||||
ret = -ENOMEM;
|
||||
ret = kmscon_hashtable_new(&font->glyphs, kmscon_direct_hash,
|
||||
kmscon_direct_equal, NULL,
|
||||
(kmscon_free_cb)kmscon_glyph_destroy);
|
||||
if (ret)
|
||||
goto err_face;
|
||||
}
|
||||
|
||||
kmscon_font_factory_ref(ff);
|
||||
font->ff = ff;
|
||||
@ -312,7 +311,7 @@ void kmscon_font_unref(struct kmscon_font *font)
|
||||
|
||||
log_debug("destroying font");
|
||||
|
||||
g_hash_table_unref(font->glyphs);
|
||||
kmscon_hashtable_free(font->glyphs);
|
||||
FT_Done_Face(font->face);
|
||||
kmscon_font_factory_unref(font->ff);
|
||||
free(font);
|
||||
@ -339,17 +338,19 @@ static int kmscon_font_lookup(struct kmscon_font *font,
|
||||
{
|
||||
struct kmscon_glyph *glyph;
|
||||
int ret;
|
||||
bool res;
|
||||
|
||||
if (!font || !out)
|
||||
return -EINVAL;
|
||||
|
||||
glyph = g_hash_table_lookup(font->glyphs, GUINT_TO_POINTER(key));
|
||||
if (!glyph) {
|
||||
res = kmscon_hashtable_find(font->glyphs, (void**)&glyph,
|
||||
(void*)(long)key);
|
||||
if (!res) {
|
||||
ret = kmscon_glyph_new(&glyph, key, font);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
g_hash_table_insert(font->glyphs, GUINT_TO_POINTER(key), glyph);
|
||||
kmscon_hashtable_insert(font->glyphs, (void*)(long)key, glyph);
|
||||
}
|
||||
|
||||
*out = glyph;
|
||||
|
@ -73,6 +73,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "unicode"
|
||||
@ -87,7 +88,7 @@ static const char default_u8[] = { 0 };
|
||||
static pthread_mutex_t table_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static uint32_t table_next_id;
|
||||
static GArray *table_index;
|
||||
static GHashTable *table_symbols;
|
||||
static struct kmscon_hashtable *table_symbols;
|
||||
|
||||
static guint hash_ucs4(gconstpointer key)
|
||||
{
|
||||
@ -140,6 +141,7 @@ static void table_unlock()
|
||||
static int table__init()
|
||||
{
|
||||
static const uint32_t *val = NULL; /* we need an lvalue for glib */
|
||||
int ret;
|
||||
|
||||
if (table_symbols)
|
||||
return 0;
|
||||
@ -155,10 +157,9 @@ static int table__init()
|
||||
/* first entry is not used so add dummy */
|
||||
g_array_append_val(table_index, val);
|
||||
|
||||
table_symbols = g_hash_table_new_full(hash_ucs4, cmp_ucs4,
|
||||
(GDestroyNotify) free, NULL);
|
||||
if (!table_symbols) {
|
||||
log_err("cannot allocate hash-table");
|
||||
ret = kmscon_hashtable_new(&table_symbols, hash_ucs4, cmp_ucs4,
|
||||
free, NULL);
|
||||
if (ret) {
|
||||
g_array_unref(table_index);
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -237,6 +238,8 @@ kmscon_symbol_t kmscon_symbol_append(kmscon_symbol_t sym, uint32_t ucs4)
|
||||
const uint32_t *ptr;
|
||||
size_t s;
|
||||
kmscon_symbol_t rsym;
|
||||
void *tmp;
|
||||
bool res;
|
||||
|
||||
table_lock();
|
||||
|
||||
@ -261,9 +264,9 @@ kmscon_symbol_t kmscon_symbol_append(kmscon_symbol_t sym, uint32_t ucs4)
|
||||
buf[s++] = ucs4;
|
||||
buf[s++] = KMSCON_UCS4_MAX + 1;
|
||||
|
||||
nsym = GPOINTER_TO_UINT(g_hash_table_lookup(table_symbols, buf));
|
||||
if (nsym) {
|
||||
rsym = nsym;
|
||||
res = kmscon_hashtable_find(table_symbols, &tmp, buf);
|
||||
if (res) {
|
||||
rsym = (uint32_t)(long)tmp;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
@ -277,7 +280,7 @@ kmscon_symbol_t kmscon_symbol_append(kmscon_symbol_t sym, uint32_t ucs4)
|
||||
|
||||
memcpy(nval, buf, s * sizeof(uint32_t));
|
||||
nsym = table_next_id++;
|
||||
g_hash_table_insert(table_symbols, nval, GUINT_TO_POINTER(nsym));
|
||||
kmscon_hashtable_insert(table_symbols, nval, (void*)(long)nsym);
|
||||
g_array_append_val(table_index, nval);
|
||||
rsym = nsym;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user