Permalink
Browse files

another try to clean up glib dependencies

  • Loading branch information...
1 parent ade8cca commit 876c1044a1d7d3721bdc2ba2efc7012734c9d864 @tagoh committed Oct 5, 2012
View
@@ -80,6 +80,7 @@ liblangtag_private_headers = \
lt-region-private.h \
lt-script-private.h \
lt-tag-private.h \
+ lt-trie.h \
lt-utils.h \
lt-variant-private.h \
lt-xml.h \
@@ -116,6 +117,7 @@ liblangtag_sources = \
lt-script-db.c \
lt-string.c \
lt-tag.c \
+ lt-trie.c \
lt-utils.c \
lt-variant.c \
lt-variant-db.c \
View
@@ -14,7 +14,7 @@
#include "config.h"
#endif
-#include <glib.h>
+#include <glib.h> /* XXX: just shut up GHashTable dependency in lt-mem.h */
#include <string.h>
#include "lt-mem.h"
View
@@ -14,14 +14,15 @@
#include "config.h"
#endif
-#include <glib.h> /* XXX: GHashTable dependency is still there */
+#include <glib.h> /* XXX: just shut up GHashTable dependency in lt-mem.h */
#include <string.h>
#include <libxml/xpath.h>
#include "lt-error.h"
#include "lt-extlang.h"
#include "lt-extlang-private.h"
#include "lt-mem.h"
#include "lt-messages.h"
+#include "lt-trie.h"
#include "lt-utils.h"
#include "lt-xml.h"
#include "lt-extlang-db.h"
@@ -36,9 +37,9 @@
* registered as ISO 639 code.
*/
struct _lt_extlang_db_t {
- lt_mem_t parent;
- lt_xml_t *xml;
- GHashTable *extlang_entries;
+ lt_mem_t parent;
+ lt_xml_t *xml;
+ lt_trie_t *extlang_entries;
};
/*< private >*/
@@ -151,9 +152,11 @@ lt_extlang_db_parse(lt_extlang_db_t *extlangdb,
lt_extlang_add_prefix(le, (const char *)prefix);
s = strdup(lt_extlang_get_tag(le));
- g_hash_table_replace(extlangdb->extlang_entries,
- lt_strlower(s),
- lt_extlang_ref(le));
+ lt_trie_replace(extlangdb->extlang_entries,
+ lt_strlower(s),
+ lt_extlang_ref(le),
+ (lt_destroy_func_t)lt_extlang_unref);
+ free(s);
bail1:
if (subtag)
xmlFree(subtag);
@@ -202,25 +205,24 @@ lt_extlang_db_new(void)
lt_error_t *err = NULL;
lt_extlang_t *le;
- retval->extlang_entries = g_hash_table_new_full(g_str_hash,
- g_str_equal,
- free,
- (GDestroyNotify)lt_extlang_unref);
+ retval->extlang_entries = lt_trie_new();
lt_mem_add_ref(&retval->parent, retval->extlang_entries,
- (lt_destroy_func_t)g_hash_table_destroy);
+ (lt_destroy_func_t)lt_trie_unref);
le = lt_extlang_create();
lt_extlang_set_tag(le, "*");
lt_extlang_set_name(le, "Wildcard entry");
- g_hash_table_replace(retval->extlang_entries,
- strdup(lt_extlang_get_tag(le)),
- le);
+ lt_trie_replace(retval->extlang_entries,
+ lt_extlang_get_tag(le),
+ le,
+ (lt_destroy_func_t)lt_extlang_unref);
le = lt_extlang_create();
lt_extlang_set_tag(le, "");
lt_extlang_set_name(le, "Empty entry");
- g_hash_table_replace(retval->extlang_entries,
- strdup(lt_extlang_get_tag(le)),
- le);
+ lt_trie_replace(retval->extlang_entries,
+ lt_extlang_get_tag(le),
+ le,
+ (lt_destroy_func_t)lt_extlang_unref);
retval->xml = lt_xml_new();
if (!retval->xml) {
@@ -294,8 +296,8 @@ lt_extlang_db_lookup(lt_extlang_db_t *extlangdb,
lt_return_val_if_fail (subtag != NULL, NULL);
s = strdup(subtag);
- retval = g_hash_table_lookup(extlangdb->extlang_entries,
- lt_strlower(s));
+ retval = lt_trie_lookup(extlangdb->extlang_entries,
+ lt_strlower(s));
free(s);
if (retval)
return lt_extlang_ref(retval);
@@ -14,14 +14,15 @@
#include "config.h"
#endif
-#include <glib.h> /* XXX: GHashTable dependency is still there */
+#include <glib.h> /* XXX: just shut up GHashTable dependency in lt-mem.h */
#include <string.h>
#include <libxml/xpath.h>
#include "lt-error.h"
#include "lt-grandfathered.h"
#include "lt-grandfathered-private.h"
#include "lt-mem.h"
#include "lt-messages.h"
+#include "lt-trie.h"
#include "lt-utils.h"
#include "lt-xml.h"
#include "lt-grandfathered-db.h"
@@ -36,9 +37,9 @@
* which has been registered under RFC 3066 and mostly deprecated.
*/
struct _lt_grandfathered_db_t {
- lt_mem_t parent;
- lt_xml_t *xml;
- GHashTable *grandfathered_entries;
+ lt_mem_t parent;
+ lt_xml_t *xml;
+ lt_trie_t *grandfathered_entries;
};
/*< private >*/
@@ -134,9 +135,11 @@ lt_grandfathered_db_parse(lt_grandfathered_db_t *grandfathereddb,
lt_grandfathered_set_preferred_tag(le, (const char *)preferred);
s = strdup(lt_grandfathered_get_tag(le));
- g_hash_table_replace(grandfathereddb->grandfathered_entries,
- lt_strlower(s),
- lt_grandfathered_ref(le));
+ lt_trie_replace(grandfathereddb->grandfathered_entries,
+ lt_strlower(s),
+ lt_grandfathered_ref(le),
+ (lt_destroy_func_t)lt_grandfathered_unref);
+ free(s);
bail1:
if (tag)
xmlFree(tag);
@@ -180,12 +183,9 @@ lt_grandfathered_db_new(void)
if (retval) {
lt_error_t *err = NULL;
- retval->grandfathered_entries = g_hash_table_new_full(g_str_hash,
- g_str_equal,
- free,
- (GDestroyNotify)lt_grandfathered_unref);
+ retval->grandfathered_entries = lt_trie_new();
lt_mem_add_ref(&retval->parent, retval->grandfathered_entries,
- (lt_destroy_func_t)g_hash_table_destroy);
+ (lt_destroy_func_t)lt_trie_unref);
retval->xml = lt_xml_new();
if (!retval->xml) {
@@ -260,8 +260,8 @@ lt_grandfathered_db_lookup(lt_grandfathered_db_t *grandfathereddb,
lt_return_val_if_fail (tag != NULL, NULL);
s = strdup(tag);
- retval = g_hash_table_lookup(grandfathereddb->grandfathered_entries,
- lt_strlower(s));
+ retval = lt_trie_lookup(grandfathereddb->grandfathered_entries,
+ lt_strlower(s));
free(s);
if (retval)
return lt_grandfathered_ref(retval);
View
@@ -14,12 +14,13 @@
#include "config.h"
#endif
-#include <glib.h> /* XXX: GHashTable dependency is still there */
+#include <glib.h> /* XXX: just shut up GHashTable dependency in lt-mem.h */
#include <string.h>
#include <libxml/xpath.h>
#include "lt-error.h"
#include "lt-mem.h"
#include "lt-messages.h"
+#include "lt-trie.h"
#include "lt-utils.h"
#include "lt-xml.h"
#include "lt-lang-private.h"
@@ -35,9 +36,9 @@
* registered as ISO 639 code.
*/
struct _lt_lang_db_t {
- lt_mem_t parent;
- lt_xml_t *xml;
- GHashTable *lang_entries;
+ lt_mem_t parent;
+ lt_xml_t *xml;
+ lt_trie_t *lang_entries;
};
/*< private >*/
@@ -162,9 +163,11 @@ lt_lang_db_parse(lt_lang_db_t *langdb,
lt_lang_set_suppress_script(le, (const char *)suppress);
s = strdup(lt_lang_get_tag(le));
- g_hash_table_replace(langdb->lang_entries,
- lt_strlower(s),
- lt_lang_ref(le));
+ lt_trie_replace(langdb->lang_entries,
+ lt_strlower(s),
+ lt_lang_ref(le),
+ (lt_destroy_func_t)lt_lang_unref);
+ free(s);
bail1:
if (subtag)
xmlFree(subtag);
@@ -215,19 +218,17 @@ lt_lang_db_new(void)
lt_error_t *err = NULL;
lt_lang_t *le;
- retval->lang_entries = g_hash_table_new_full(g_str_hash,
- g_str_equal,
- free,
- (GDestroyNotify)lt_lang_unref);
+ retval->lang_entries = lt_trie_new();
lt_mem_add_ref(&retval->parent, retval->lang_entries,
- (lt_destroy_func_t)g_hash_table_destroy);
+ (lt_destroy_func_t)lt_trie_unref);
le = lt_lang_create();
lt_lang_set_tag(le, "*");
lt_lang_set_name(le, "Wildcard entry");
- g_hash_table_replace(retval->lang_entries,
- strdup(lt_lang_get_tag(le)),
- le);
+ lt_trie_replace(retval->lang_entries,
+ lt_lang_get_tag(le),
+ le,
+ (lt_destroy_func_t)lt_lang_unref);
retval->xml = lt_xml_new();
if (!retval->xml) {
@@ -302,7 +303,7 @@ lt_lang_db_lookup(lt_lang_db_t *langdb,
lt_return_val_if_fail (subtag != NULL, NULL);
s = strdup(subtag);
- retval = g_hash_table_lookup(langdb->lang_entries, lt_strlower(s));
+ retval = lt_trie_lookup(langdb->lang_entries, lt_strlower(s));
free(s);
if (retval)
return lt_lang_ref(retval);
@@ -14,7 +14,7 @@
#include "config.h"
#endif
-#include <glib.h> /* XXX: GHashTable dependency is still there */
+#include <glib.h> /* XXX: just shut up GHashTable dependency in lt-mem.h */
#include <stdlib.h>
#include <string.h>
#include <libxml/xpath.h>
@@ -23,6 +23,7 @@
#include "lt-redundant-private.h"
#include "lt-mem.h"
#include "lt-messages.h"
+#include "lt-trie.h"
#include "lt-utils.h"
#include "lt-xml.h"
#include "lt-redundant-db.h"
@@ -38,9 +39,9 @@
* or RFC 5646.
*/
struct _lt_redundant_db_t {
- lt_mem_t parent;
- lt_xml_t *xml;
- GHashTable *redundant_entries;
+ lt_mem_t parent;
+ lt_xml_t *xml;
+ lt_trie_t *redundant_entries;
};
/*< private >*/
@@ -136,9 +137,11 @@ lt_redundant_db_parse(lt_redundant_db_t *redundantdb,
lt_redundant_set_preferred_tag(le, (const char *)preferred);
s = strdup(lt_redundant_get_tag(le));
- g_hash_table_replace(redundantdb->redundant_entries,
- lt_strlower(s),
- lt_redundant_ref(le));
+ lt_trie_replace(redundantdb->redundant_entries,
+ lt_strlower(s),
+ lt_redundant_ref(le),
+ (lt_destroy_func_t)lt_redundant_unref);
+ free(s);
bail1:
if (tag)
xmlFree(tag);
@@ -182,12 +185,9 @@ lt_redundant_db_new(void)
if (retval) {
lt_error_t *err = NULL;
- retval->redundant_entries = g_hash_table_new_full(g_str_hash,
- g_str_equal,
- free,
- (GDestroyNotify)lt_redundant_unref);
+ retval->redundant_entries = lt_trie_new();
lt_mem_add_ref(&retval->parent, retval->redundant_entries,
- (lt_destroy_func_t)g_hash_table_destroy);
+ (lt_destroy_func_t)lt_trie_unref);
retval->xml = lt_xml_new();
if (!retval->xml) {
@@ -262,8 +262,8 @@ lt_redundant_db_lookup(lt_redundant_db_t *redundantdb,
lt_return_val_if_fail (tag != NULL, NULL);
s = strdup(tag);
- retval = g_hash_table_lookup(redundantdb->redundant_entries,
- lt_strlower(s));
+ retval = lt_trie_lookup(redundantdb->redundant_entries,
+ lt_strlower(s));
free(s);
if (retval)
return lt_redundant_ref(retval);
Oops, something went wrong.

0 comments on commit 876c104

Please sign in to comment.