summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-05-12 23:49:08 +0000
committerDavid Robillard <d@drobilla.net>2011-05-12 23:49:08 +0000
commitdfb0795932f0e06873c538c13dcdd3a4d9e3b5b2 (patch)
tree58ac9ced7f6bc8afb4c180f98e77881fd6d143bb
parent22f5f5c7e32b043433103edb404bfbe43effa15d (diff)
downloadsord-dfb0795932f0e06873c538c13dcdd3a4d9e3b5b2.tar.gz
sord-dfb0795932f0e06873c538c13dcdd3a4d9e3b5b2.tar.bz2
sord-dfb0795932f0e06873c538c13dcdd3a4d9e3b5b2.zip
Performance improvements for sord_node_from_serd_node.
git-svn-id: http://svn.drobilla.net/sord/trunk@112 3d64ff67-21c5-427c-a301-fe4f08042e5a
-rw-r--r--src/sord.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/sord.c b/src/sord.c
index 4bd191a..edab095 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -822,12 +822,11 @@ sord_intern_lang(SordWorld* world, const char* lang)
{
if (lang) {
char* ilang = g_hash_table_lookup(world->langs, lang);
- if (ilang) {
- lang = ilang;
- } else {
+ if (!ilang) {
ilang = g_strdup(lang);
g_hash_table_insert(world->langs, ilang, ilang);
}
+ lang = ilang;
}
return lang;
}
@@ -1017,22 +1016,26 @@ sord_node_from_serd_node(SordWorld* world,
sn->n_bytes,
sn->n_chars,
sn->flags,
- sord_intern_lang(world, (const char*)lang->buf));
+ (const char*)lang->buf);
sord_node_free(world, datatype_node);
return ret;
- case SERD_URI: {
- SerdURI base_uri;
- serd_env_get_base_uri(env, &base_uri);
- SerdURI abs_uri;
- SerdNode abs_uri_node = serd_node_new_uri_from_node(
- sn, &base_uri, &abs_uri);
- SordNode* ret = sord_new_uri_counted(world,
- abs_uri_node.buf,
- abs_uri_node.n_bytes,
- abs_uri_node.n_chars);
- serd_node_free(&abs_uri_node);
- return ret;
- }
+ case SERD_URI:
+ if (serd_uri_string_has_scheme(sn->buf)) {
+ return sord_new_uri_counted(world,
+ sn->buf, sn->n_bytes, sn->n_chars);
+ } else {
+ SerdURI base_uri;
+ serd_env_get_base_uri(env, &base_uri);
+ SerdURI abs_uri;
+ SerdNode abs_uri_node = serd_node_new_uri_from_node(
+ sn, &base_uri, &abs_uri);
+ SordNode* ret = sord_new_uri_counted(world,
+ abs_uri_node.buf,
+ abs_uri_node.n_bytes,
+ abs_uri_node.n_chars);
+ serd_node_free(&abs_uri_node);
+ return ret;
+ }
case SERD_CURIE: {
SerdChunk uri_prefix;
SerdChunk uri_suffix;
@@ -1041,14 +1044,13 @@ sord_node_from_serd_node(SordWorld* world,
return NULL;
}
const size_t uri_len = uri_prefix.len + uri_suffix.len;
- uint8_t* buf = malloc(uri_len + 1);
+ uint8_t buf[uri_len + 1];
memcpy(buf, uri_prefix.buf, uri_prefix.len);
memcpy(buf + uri_prefix.len, uri_suffix.buf, uri_suffix.len);
buf[uri_len] = '\0';
SordNode* ret = sord_new_uri_counted(
world, buf, uri_prefix.len + uri_suffix.len,
uri_prefix.len + uri_suffix.len); // FIXME: UTF-8
- free(buf);
return ret;
}
case SERD_BLANK_ID: