summaryrefslogtreecommitdiffstats
path: root/src/sord.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-04-24 01:53:13 +0000
committerDavid Robillard <d@drobilla.net>2011-04-24 01:53:13 +0000
commitc7674e42ab2389265a00ecfe94d42f0a521eb81b (patch)
treeb1f8a87f4402dd97309fe44072a7cebeb54db939 /src/sord.c
parent9ad2e0bdec306d80357a642271fbde1f8f02ec45 (diff)
downloadsord-c7674e42ab2389265a00ecfe94d42f0a521eb81b.tar.gz
sord-c7674e42ab2389265a00ecfe94d42f0a521eb81b.tar.bz2
sord-c7674e42ab2389265a00ecfe94d42f0a521eb81b.zip
Minor node comparison performance improvements (fast cases).
git-svn-id: http://svn.drobilla.net/sord/trunk@85 3d64ff67-21c5-427c-a301-fe4f08042e5a
Diffstat (limited to 'src/sord.c')
-rw-r--r--src/sord.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/sord.c b/src/sord.c
index b503cdc..4a8d94c 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -150,10 +150,11 @@ sord_literal_equal(const void* a, const void* b)
{
SordNode a_node = (SordNode)a;
SordNode b_node = (SordNode)b;
- return g_str_equal(sord_node_get_string(a_node),
- sord_node_get_string(b_node))
- && (a_node->lang == b_node->lang)
- && sord_node_equals(a_node->datatype, b_node->datatype);
+ return (a_node == b_node)
+ || (g_str_equal(sord_node_get_string(a_node),
+ sord_node_get_string(b_node))
+ && (a_node->lang == b_node->lang)
+ && (a_node->datatype == b_node->datatype));
}
SordWorld
@@ -179,12 +180,10 @@ sord_world_free(SordWorld world)
static inline int
sord_node_compare(const SordNode a, const SordNode b)
{
- if (!a && b) {
- return 1;
- } else if (a && !b) {
- return -1;
- } else if (!a && !b) {
+ if (a == b) {
return 0;
+ } else if (!a || !b) {
+ return a - b;
} else if (a->type != b->type) {
return a->type - b->type;
}
@@ -201,10 +200,8 @@ sord_node_compare(const SordNode a, const SordNode b)
cmp = sord_node_compare(a->datatype, b->datatype);
}
if (cmp == 0) {
- if (!a->lang && b->lang) {
- cmp = 1;
- } else if (a->lang && !b->lang) {
- cmp = -1;
+ if (!a->lang || !b->lang) {
+ cmp = a->lang - b->lang;
} else {
cmp = strcmp(a->lang, b->lang);
}