summaryrefslogtreecommitdiffstats
path: root/src/plugin.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-04-29 23:02:24 +0000
committerDavid Robillard <d@drobilla.net>2011-04-29 23:02:24 +0000
commit2aebf86c27288254da4765116686101a88840cbd (patch)
tree78beebd64ac17141a804471896f8389285395f6e /src/plugin.c
parentf89cead131a61c0b58bc4e706df339db3f1b9965 (diff)
downloadlilv-2aebf86c27288254da4765116686101a88840cbd.tar.gz
lilv-2aebf86c27288254da4765116686101a88840cbd.tar.bz2
lilv-2aebf86c27288254da4765116686101a88840cbd.zip
Faster implementations of lilv_plugin_get_one and lilv_plugin_get_unique.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3239 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/plugin.c')
-rw-r--r--src/plugin.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 5841bd2..32c40da 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -81,35 +81,31 @@ lilv_plugin_free(LilvPlugin* p)
free(p);
}
-LilvNode*
-lilv_plugin_get_unique(const LilvPlugin* p,
- const SordNode* subject,
- const SordNode* predicate)
+static LilvNode*
+lilv_plugin_get_one(const LilvPlugin* p,
+ const SordNode* subject,
+ const SordNode* predicate)
{
- LilvNodes* values = lilv_world_query_values(p->world,
- subject, predicate, NULL);
- if (!values || lilv_nodes_size(values) != 1) {
- LILV_ERRORF("Port does not have exactly one `%s' property\n",
- sord_node_get_string(predicate));
- return NULL;
+ LilvNode* ret = NULL;
+ SordIter* stream = lilv_world_query(p->world, subject, predicate, NULL);
+ if (!lilv_matches_end(stream)) {
+ ret = lilv_node_new_from_node(p->world, lilv_match_object(stream));
}
- LilvNode* ret = lilv_node_duplicate(lilv_nodes_get_first(values));
- lilv_nodes_free(values);
+ lilv_match_end(stream);
return ret;
}
-static LilvNode*
-lilv_plugin_get_one(const LilvPlugin* p,
- const SordNode* subject,
- const SordNode* predicate)
+LilvNode*
+lilv_plugin_get_unique(const LilvPlugin* p,
+ const SordNode* subject,
+ const SordNode* predicate)
{
- LilvNodes* values = lilv_world_query_values(p->world,
- subject, predicate, NULL);
- if (!values) {
- return NULL;
+ LilvNode* ret = lilv_plugin_get_one(p, subject, predicate);
+ if (!ret) {
+ LILV_ERRORF("Multiple values found for (%s %s ...) property\n",
+ sord_node_get_string(subject),
+ sord_node_get_string(predicate));
}
- LilvNode* ret = lilv_node_duplicate(lilv_nodes_get_first(values));
- lilv_nodes_free(values);
return ret;
}