summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-31 01:34:19 +0000
committerDavid Robillard <d@drobilla.net>2011-01-31 01:34:19 +0000
commit15f9b09510615f1732e7eb043ac587673b4edc4a (patch)
tree7dde76127c8b274bbb55f27e2c01cbe2476d3779
parentd716c6d5e7c622d238d460a32ad7d02845fbc4d4 (diff)
downloadlilv-15f9b09510615f1732e7eb043ac587673b4edc4a.tar.gz
lilv-15f9b09510615f1732e7eb043ac587673b4edc4a.tar.bz2
lilv-15f9b09510615f1732e7eb043ac587673b4edc4a.zip
Reduce heavy use of librdf_new_node_from* functions.
Store a librdf_node, rather than a librdf_uri, for a URI SLV2Value (further reducing the use of librdf_uri). git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2882 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/plugin.c72
-rw-r--r--src/port.c2
-rw-r--r--src/query.c5
-rw-r--r--src/slv2_internal.h7
-rw-r--r--src/value.c22
-rw-r--r--src/world.c57
6 files changed, 91 insertions, 74 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 9d08167..bb18cb8 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -178,8 +178,8 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
SLV2Matches ports = slv2_plugin_find_statements(
p,
- librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
- librdf_new_node_from_node(p->world->lv2_port_node),
+ p->plugin_uri->val.uri_val,
+ p->world->lv2_port_node,
NULL);
FOREACH_MATCH(ports) {
@@ -222,10 +222,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
}
SLV2Matches types = slv2_plugin_find_statements(
- p,
- librdf_new_node_from_node(port),
- librdf_new_node_from_node(p->world->rdf_a_node),
- NULL);
+ p, port, p->world->rdf_a_node, NULL);
FOREACH_MATCH(types) {
librdf_node* type = MATCH_OBJECT(types);
if (librdf_node_is_resource(type)) {
@@ -267,8 +264,8 @@ slv2_plugin_load(SLV2Plugin p)
// Parse all the plugin's data files into RDF model
for (unsigned i=0; i < slv2_values_size(p->data_uris); ++i) {
- SLV2Value data_uri_val = slv2_values_get_at(p->data_uris, i);
- librdf_uri* data_uri = slv2_value_as_librdf_uri(data_uri_val);
+ SLV2Value data_uri_val = slv2_values_get_at(p->data_uris, i);
+ librdf_uri* data_uri = slv2_value_as_librdf_uri(data_uri_val);
librdf_parser_parse_into_model(p->world->parser, data_uri, data_uri, p->rdf);
}
@@ -338,8 +335,8 @@ slv2_plugin_get_library_uri(SLV2Plugin p)
// <plugin> lv2:binary ?binary
SLV2Matches results = slv2_plugin_find_statements(
p,
- librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
- librdf_new_node_from_node(p->world->lv2_binary_node),
+ p->plugin_uri->val.uri_val,
+ p->world->lv2_binary_node,
NULL);
FOREACH_MATCH(results) {
librdf_node* binary_node = MATCH_OBJECT(results);
@@ -369,8 +366,8 @@ slv2_plugin_get_class(SLV2Plugin p)
// <plugin> a ?class
SLV2Matches results = slv2_plugin_find_statements(
p,
- librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
- librdf_new_node_from_node(p->world->rdf_a_node),
+ p->plugin_uri->val.uri_val,
+ p->world->rdf_a_node,
NULL);
FOREACH_MATCH(results) {
librdf_node* class_node = librdf_new_node_from_node(MATCH_OBJECT(results));
@@ -500,10 +497,11 @@ slv2_plugin_get_value_by_qname_i18n(SLV2Plugin p,
SLV2Matches results = slv2_plugin_find_statements(
p,
- librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
+ p->plugin_uri->val.uri_val,
pred_node,
NULL);
+ librdf_free_node(pred_node);
free(pred_uri);
return slv2_values_from_stream_i18n(p, results);
@@ -525,15 +523,14 @@ slv2_plugin_get_value_for_subject(SLV2Plugin p,
}
librdf_node* subject_node = (slv2_value_is_uri(subject))
- ? librdf_new_node_from_uri(
- p->world->world, subject->val.uri_val)
+ ? librdf_new_node_from_node(subject->val.uri_val)
: librdf_new_node_from_blank_identifier(
p->world->world, (const uint8_t*)slv2_value_as_blank(subject));
return slv2_plugin_query_node(
p,
subject_node,
- librdf_new_node_from_uri(p->world->world, predicate->val.uri_val));
+ librdf_new_node_from_node(predicate->val.uri_val));
}
@@ -609,8 +606,8 @@ slv2_plugin_has_latency(SLV2Plugin p)
{
SLV2Matches ports = slv2_plugin_find_statements(
p,
- librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
- librdf_new_node_from_node(p->world->lv2_port_node),
+ p->plugin_uri->val.uri_val,
+ p->world->lv2_port_node,
NULL);
bool ret = false;
@@ -618,11 +615,9 @@ slv2_plugin_has_latency(SLV2Plugin p)
librdf_node* port = MATCH_OBJECT(ports);
SLV2Matches reports_latency = slv2_plugin_find_statements(
p,
- librdf_new_node_from_node(port),
- librdf_new_node_from_node(p->world->lv2_portproperty_node),
- librdf_new_node_from_uri_string(p->world->world,
- SLV2_NS_LV2 "reportsLatency"));
-
+ port,
+ p->world->lv2_portproperty_node,
+ p->world->lv2_reportslatency_node);
if (!slv2_matches_end(reports_latency)) {
ret = true;
break;
@@ -641,8 +636,8 @@ slv2_plugin_get_latency_port_index(SLV2Plugin p)
{
SLV2Matches ports = slv2_plugin_find_statements(
p,
- librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
- librdf_new_node_from_node(p->world->lv2_port_node),
+ p->plugin_uri->val.uri_val,
+ p->world->lv2_port_node,
NULL);
uint32_t ret = 0;
@@ -650,11 +645,9 @@ slv2_plugin_get_latency_port_index(SLV2Plugin p)
librdf_node* port = MATCH_OBJECT(ports);
SLV2Matches reports_latency = slv2_plugin_find_statements(
p,
- librdf_new_node_from_node(port),
- librdf_new_node_from_node(p->world->lv2_portproperty_node),
- librdf_new_node_from_uri_string(p->world->world,
- SLV2_NS_LV2 "reportsLatency"));
-
+ port,
+ p->world->lv2_portproperty_node,
+ p->world->lv2_reportslatency_node);
if (!slv2_matches_end(reports_latency)) {
SLV2Value index = slv2_plugin_get_unique(
p, port, p->world->lv2_index_node);
@@ -751,12 +744,17 @@ slv2_plugin_get_port_by_symbol(SLV2Plugin p,
static librdf_node*
slv2_plugin_get_author(SLV2Plugin p)
{
+ librdf_node* doap_maintainer = librdf_new_node_from_uri_string(
+ p->world->world, NS_DOAP "maintainer");
+
SLV2Matches maintainers = slv2_plugin_find_statements(
p,
- librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
- librdf_new_node_from_uri_string(p->world->world, NS_DOAP "maintainer"),
+ p->plugin_uri->val.uri_val,
+ doap_maintainer,
NULL);
+ librdf_free_node(doap_maintainer);
+
if (slv2_matches_end(maintainers)) {
return NULL;
}
@@ -812,12 +810,16 @@ slv2_plugin_get_uis(SLV2Plugin p)
{
#define NS_UI (const uint8_t*)"http://lv2plug.in/ns/extensions/ui#"
+ librdf_node* ui_ui = librdf_new_node_from_uri_string(
+ p->world->world, NS_UI "ui");
+
SLV2UIs result = slv2_uis_new();
SLV2Matches uis = slv2_plugin_find_statements(
p,
- librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
- librdf_new_node_from_uri_string(p->world->world, NS_UI "ui"),
+ p->plugin_uri->val.uri_val,
+ ui_ui,
NULL);
+
FOREACH_MATCH(uis) {
librdf_node* ui = MATCH_OBJECT(uis);
@@ -851,6 +853,8 @@ slv2_plugin_get_uis(SLV2Plugin p)
}
END_MATCH(uis);
+ librdf_free_node(ui_ui);
+
if (slv2_uis_size(result) > 0) {
return result;
} else {
diff --git a/src/port.c b/src/port.c
index 28a5036..19692cc 100644
--- a/src/port.c
+++ b/src/port.c
@@ -70,7 +70,7 @@ slv2_port_get_node(SLV2Plugin p,
{
SLV2Matches ports = slv2_plugin_find_statements(
p,
- librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
+ librdf_new_node_from_node(p->plugin_uri->val.uri_val),
librdf_new_node_from_node(p->world->lv2_port_node),
NULL);
librdf_node* ret = NULL;
diff --git a/src/query.c b/src/query.c
index ac49ece..e7f6565 100644
--- a/src/query.c
+++ b/src/query.c
@@ -37,7 +37,10 @@ slv2_plugin_find_statements(SLV2Plugin plugin,
{
slv2_plugin_load_if_necessary(plugin);
librdf_statement* q = librdf_new_statement_from_nodes(
- plugin->world->world, subject, predicate, object);
+ plugin->world->world,
+ subject ? librdf_new_node_from_node(subject) : NULL,
+ predicate ? librdf_new_node_from_node(predicate) : NULL,
+ object ? librdf_new_node_from_node(object) : NULL);
librdf_stream* results = librdf_model_find_statements(plugin->rdf, q);
librdf_free_statement(q);
return results;
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index dd55aca..eba23b7 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -174,6 +174,7 @@ struct _SLV2World {
librdf_node* lv2_maximum_node;
librdf_node* lv2_port_node;
librdf_node* lv2_portproperty_node;
+ librdf_node* lv2_reportslatency_node;
librdf_node* lv2_index_node;
librdf_node* lv2_symbol_node;
librdf_node* rdf_a_node;
@@ -247,9 +248,9 @@ struct _SLV2Value {
SLV2ValueType type;
char* str_val; ///< always present
union {
- int int_val;
- float float_val;
- librdf_uri* uri_val;
+ int int_val;
+ float float_val;
+ librdf_node* uri_val;
} val;
};
diff --git a/src/value.c b/src/value.c
index b1e141c..4f9d606 100644
--- a/src/value.c
+++ b/src/value.c
@@ -75,9 +75,11 @@ slv2_value_new(SLV2World world, SLV2ValueType type, const char* str)
switch (type) {
case SLV2_VALUE_URI:
- val->val.uri_val = librdf_new_uri(world->world, (const uint8_t*)str);
+ val->val.uri_val = librdf_new_node_from_uri_string(
+ world->world, (const uint8_t*)str);
assert(val->val.uri_val);
- val->str_val = (char*)librdf_uri_as_string(val->val.uri_val);
+ val->str_val = (char*)librdf_uri_as_string(
+ librdf_node_get_uri(val->val.uri_val));
break;
case SLV2_VALUE_QNAME_UNUSED:
case SLV2_VALUE_BLANK:
@@ -149,8 +151,9 @@ slv2_value_new_librdf_uri(SLV2World world, librdf_node* node)
assert(node && librdf_node_is_resource(node));
SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value));
val->type = SLV2_VALUE_URI;
- val->val.uri_val = librdf_new_uri_from_uri(librdf_node_get_uri(node));
- val->str_val = (char*)librdf_uri_as_string(val->val.uri_val);
+ val->val.uri_val = librdf_new_node_from_node(node);
+ val->str_val = (char*)librdf_uri_as_string(
+ librdf_node_get_uri(val->val.uri_val));
return val;
}
@@ -201,8 +204,9 @@ slv2_value_duplicate(SLV2Value val)
result->type = val->type;
if (val->type == SLV2_VALUE_URI) {
- result->val.uri_val = librdf_new_uri_from_uri(val->val.uri_val);
- result->str_val = (char*)librdf_uri_as_string(val->val.uri_val);
+ result->val.uri_val = librdf_new_node_from_node(val->val.uri_val);
+ result->str_val = (char*)librdf_uri_as_string(
+ librdf_node_get_uri(val->val.uri_val));
} else {
result->str_val = strdup(val->str_val);
result->val = val->val;
@@ -217,7 +221,7 @@ slv2_value_free(SLV2Value val)
{
if (val) {
if (val->type == SLV2_VALUE_URI)
- librdf_free_uri(val->val.uri_val);
+ librdf_free_node(val->val.uri_val);
else
free(val->str_val);
@@ -238,7 +242,7 @@ slv2_value_equals(SLV2Value value, SLV2Value other)
switch (value->type) {
case SLV2_VALUE_URI:
- return (librdf_uri_equals(value->val.uri_val, other->val.uri_val) != 0);
+ return (librdf_node_equals(value->val.uri_val, other->val.uri_val) != 0);
case SLV2_VALUE_BLANK:
case SLV2_VALUE_STRING:
case SLV2_VALUE_QNAME_UNUSED:
@@ -322,7 +326,7 @@ librdf_uri*
slv2_value_as_librdf_uri(SLV2Value value)
{
assert(slv2_value_is_uri(value));
- return value->val.uri_val;
+ return librdf_node_get_uri(value->val.uri_val);
}
diff --git a/src/world.c b/src/world.c
index 77b3c7f..28868db 100644
--- a/src/world.c
+++ b/src/world.c
@@ -59,27 +59,28 @@ slv2_world_new_internal(SLV2World world)
#define NEW_URI(uri) librdf_new_node_from_uri_string(world->world, uri);
- world->dyn_manifest_node = NEW_URI(NS_DYNMAN "DynManifest");
- world->lv2_specification_node = NEW_URI(SLV2_NS_LV2 "Specification");
- world->lv2_plugin_node = NEW_URI(SLV2_NS_LV2 "Plugin");
- world->lv2_binary_node = NEW_URI(SLV2_NS_LV2 "binary");
- world->lv2_default_node = NEW_URI(SLV2_NS_LV2 "default");
- world->lv2_minimum_node = NEW_URI(SLV2_NS_LV2 "minimum");
- world->lv2_maximum_node = NEW_URI(SLV2_NS_LV2 "maximum");
- world->lv2_port_node = NEW_URI(SLV2_NS_LV2 "port");
- world->lv2_portproperty_node = NEW_URI(SLV2_NS_LV2 "portProperty");
- world->lv2_index_node = NEW_URI(SLV2_NS_LV2 "index");
- world->lv2_symbol_node = NEW_URI(SLV2_NS_LV2 "symbol");
- world->rdf_a_node = NEW_URI(SLV2_NS_RDF "type");
- world->rdf_value_node = NEW_URI(SLV2_NS_RDF "value");
- world->rdfs_class_node = NEW_URI(SLV2_NS_RDFS "Class");
- world->rdfs_label_node = NEW_URI(SLV2_NS_RDFS "label");
- world->rdfs_seealso_node = NEW_URI(SLV2_NS_RDFS "seeAlso");
- world->rdfs_subclassof_node = NEW_URI(SLV2_NS_RDFS "subClassOf");
- world->slv2_bundleuri_node = NEW_URI(SLV2_NS_SLV2 "bundleURI");
- world->slv2_dmanifest_node = NEW_URI(SLV2_NS_SLV2 "dynamic-manifest");
- world->xsd_integer_node = NEW_URI(SLV2_NS_XSD "integer");
- world->xsd_decimal_node = NEW_URI(SLV2_NS_XSD "decimal");
+ world->dyn_manifest_node = NEW_URI(NS_DYNMAN "DynManifest");
+ world->lv2_specification_node = NEW_URI(SLV2_NS_LV2 "Specification");
+ world->lv2_plugin_node = NEW_URI(SLV2_NS_LV2 "Plugin");
+ world->lv2_binary_node = NEW_URI(SLV2_NS_LV2 "binary");
+ world->lv2_default_node = NEW_URI(SLV2_NS_LV2 "default");
+ world->lv2_minimum_node = NEW_URI(SLV2_NS_LV2 "minimum");
+ world->lv2_maximum_node = NEW_URI(SLV2_NS_LV2 "maximum");
+ world->lv2_port_node = NEW_URI(SLV2_NS_LV2 "port");
+ world->lv2_portproperty_node = NEW_URI(SLV2_NS_LV2 "portProperty");
+ world->lv2_reportslatency_node = NEW_URI(SLV2_NS_LV2 "reportsLatency");
+ world->lv2_index_node = NEW_URI(SLV2_NS_LV2 "index");
+ world->lv2_symbol_node = NEW_URI(SLV2_NS_LV2 "symbol");
+ world->rdf_a_node = NEW_URI(SLV2_NS_RDF "type");
+ world->rdf_value_node = NEW_URI(SLV2_NS_RDF "value");
+ world->rdfs_class_node = NEW_URI(SLV2_NS_RDFS "Class");
+ world->rdfs_label_node = NEW_URI(SLV2_NS_RDFS "label");
+ world->rdfs_seealso_node = NEW_URI(SLV2_NS_RDFS "seeAlso");
+ world->rdfs_subclassof_node = NEW_URI(SLV2_NS_RDFS "subClassOf");
+ world->slv2_bundleuri_node = NEW_URI(SLV2_NS_SLV2 "bundleURI");
+ world->slv2_dmanifest_node = NEW_URI(SLV2_NS_SLV2 "dynamic-manifest");
+ world->xsd_integer_node = NEW_URI(SLV2_NS_XSD "integer");
+ world->xsd_decimal_node = NEW_URI(SLV2_NS_XSD "decimal");
world->lv2_plugin_class = slv2_plugin_class_new(
world, NULL, world->lv2_plugin_node, "Plugin");
@@ -171,6 +172,7 @@ slv2_world_free(SLV2World world)
librdf_free_node(world->lv2_maximum_node);
librdf_free_node(world->lv2_port_node);
librdf_free_node(world->lv2_portproperty_node);
+ librdf_free_node(world->lv2_reportslatency_node);
librdf_free_node(world->lv2_index_node);
librdf_free_node(world->lv2_symbol_node);
librdf_free_node(world->rdf_a_node);
@@ -243,7 +245,8 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
}
librdf_uri* manifest_uri = librdf_new_uri_relative_to_base(
- bundle_uri->val.uri_val, (const uint8_t*)"manifest.ttl");
+ librdf_node_get_uri(bundle_uri->val.uri_val),
+ (const uint8_t*)"manifest.ttl");
/* Parse the manifest into a temporary model */
librdf_storage* manifest_storage = slv2_world_new_storage(world);
@@ -307,8 +310,10 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
FILE* fd = tmpfile();
get_subjects_func(handle, fd);
rewind(fd);
- librdf_parser_parse_file_handle_into_model(world->parser,
- fd, 0, bundle_uri->val.uri_val, dyn_manifest_model);
+ librdf_parser_parse_file_handle_into_model(
+ world->parser, fd, 0,
+ librdf_node_get_uri(bundle_uri->val.uri_val),
+ dyn_manifest_model);
fclose(fd);
// ?plugin a lv2:Plugin
@@ -359,7 +364,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
world->model,
librdf_new_node_from_node(plugin),
librdf_new_node_from_uri_string(world->world, SLV2_NS_SLV2 "bundleURI"),
- librdf_new_node_from_uri(world->world, bundle_uri->val.uri_val));
+ librdf_new_node_from_node(bundle_uri->val.uri_val));
}
END_MATCH(results);
@@ -384,7 +389,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
world->model,
librdf_new_node_from_node(spec),
librdf_new_node_from_uri_string(world->world, SLV2_NS_SLV2 "bundleURI"),
- librdf_new_node_from_uri(world->world, bundle_uri->val.uri_val));
+ librdf_new_node_from_node(bundle_uri->val.uri_val));
}
END_MATCH(results);