diff options
author | David Robillard <d@drobilla.net> | 2012-01-05 17:05:48 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-01-05 17:05:48 +0000 |
commit | 9c6d55b0c831370562ced1577fb3d4934cf7dbca (patch) | |
tree | 81a1b6eac615edccf3890dde77a5671bad24e560 /src/sord.c | |
parent | 33fc3600004690a9e1868b5fb1ca81da79c2fd61 (diff) | |
download | sord-9c6d55b0c831370562ced1577fb3d4934cf7dbca.tar.gz sord-9c6d55b0c831370562ced1577fb3d4934cf7dbca.tar.bz2 sord-9c6d55b0c831370562ced1577fb3d4934cf7dbca.zip |
Fix comparison of typed literals.
Take advantage of interning in sord_node_equals().
Improve test coverage.
git-svn-id: http://svn.drobilla.net/sord/trunk@185 3d64ff67-21c5-427c-a301-fe4f08042e5a
Diffstat (limited to 'src/sord.c')
-rw-r--r-- | src/sord.c | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -199,16 +199,17 @@ sord_world_free(SordWorld* world) free(world); } +/** Compare nodes, considering NULL a wildcard match. */ static inline int sord_node_compare(const SordNode* a, const SordNode* b) { if (a == b || !a || !b) { - return 0; + return 0; // Exact or wildcard match } else if (a->node.type != b->node.type) { return a->node.type - b->node.type; } - int cmp; + int cmp = 0; switch (a->node.type) { case SERD_URI: case SERD_BLANK: @@ -217,7 +218,13 @@ sord_node_compare(const SordNode* a, const SordNode* b) cmp = strcmp((const char*)sord_node_get_string(a), (const char*)sord_node_get_string(b)); if (cmp == 0) { - cmp = sord_node_compare(a->datatype, b->datatype); + // Note: Can't use sord_node_compare here since it does wildcards + if (!a->datatype || !b->datatype) { + cmp = a->datatype - b->datatype; + } else { + cmp = strcmp((const char*)a->datatype->node.buf, + (const char*)b->datatype->node.buf); + } } if (cmp == 0) { if (!a->lang || !b->lang) { @@ -226,23 +233,16 @@ sord_node_compare(const SordNode* a, const SordNode* b) cmp = strcmp(a->lang, b->lang); } } - return cmp; default: - break; // never reached + break; } - assert(false); - return 0; + return cmp; } bool sord_node_equals(const SordNode* a, const SordNode* b) { - if (!a || !b) { - return (a == b); - } else { - // FIXME: nodes are interned, this can be much faster - return (a == b) || (sord_node_compare(a, b) == 0); - } + return a == b; // Nodes are interned } /** Return true iff IDs are equivalent, or one is a wildcard */ @@ -605,6 +605,10 @@ sord_new(SordWorld* world, unsigned indices, bool graphs) sord->indices[DEFAULT_ORDER] = zix_tree_new( false, sord_quad_compare, (void*)orderings[DEFAULT_ORDER]); } + if (graphs && !sord->indices[DEFAULT_GRAPH_ORDER]) { + sord->indices[DEFAULT_GRAPH_ORDER] = zix_tree_new( + false, sord_quad_compare, (void*)orderings[DEFAULT_GRAPH_ORDER]); + } return sord; } |