summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-29 19:33:26 +0000
committerDavid Robillard <d@drobilla.net>2011-01-29 19:33:26 +0000
commit2ddc5e1455c910dbe6ce7be22cac07b66511b6d9 (patch)
treef233a6f43a47ddbf06340a51d3eb23e5e72ce56a
parent41500472d1c675161c025b973a36e7a534735771 (diff)
downloadlilv-2ddc5e1455c910dbe6ce7be22cac07b66511b6d9.tar.gz
lilv-2ddc5e1455c910dbe6ce7be22cac07b66511b6d9.tar.bz2
lilv-2ddc5e1455c910dbe6ce7be22cac07b66511b6d9.zip
Simplify/shrink plugin discovery code by assuming search results are sorted.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2855 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/world.c48
1 files changed, 10 insertions, 38 deletions
diff --git a/src/world.c b/src/world.c
index b00baad..342b955 100644
--- a/src/world.c
+++ b/src/world.c
@@ -657,48 +657,20 @@ slv2_world_load_all(SLV2World world)
librdf_free_stream(bundles);
// Add a new plugin to the world
- SLV2Plugin plugin = NULL;
SLV2Value uri = slv2_value_new_librdf_uri(world, plugin_uri);
const unsigned n_plugins = raptor_sequence_size(world->plugins);
- if (n_plugins == 0) {
- plugin = slv2_plugin_new(world, uri, bundle_uri);
- raptor_sequence_push(world->plugins, plugin);
- } else {
- SLV2Plugin first = raptor_sequence_get_at(world->plugins, 0);
- SLV2Plugin prev = raptor_sequence_get_at(world->plugins, n_plugins - 1);
-
- /* TODO: It should be (is?) guaranteed the plugin results are in order,
- is this necessary? IIRC old redland didn't for the old SPARQL query
- that was here, but this no longer applies...
- */
- if (strcmp(
- slv2_value_as_string(slv2_plugin_get_uri(prev)),
- (const char*)librdf_uri_as_string(plugin_uri)) < 0) {
- // If the URI is > the last in the list, just append (avoid sort)
- plugin = slv2_plugin_new(world, uri, bundle_uri);
- raptor_sequence_push(world->plugins, plugin);
-
- } else if (strcmp(
- slv2_value_as_string(slv2_plugin_get_uri(first)),
- (const char*)librdf_uri_as_string(plugin_uri)) > 0) {
- // If the URI is < the first in the list, just prepend (avoid sort)
- plugin = slv2_plugin_new(world, uri, bundle_uri);
- raptor_sequence_shift(world->plugins, plugin);
-
- } else {
- // Otherwise we're getting unsorted results, append and sort :/
- plugin = slv2_plugins_get_by_uri(world->plugins, uri);
- if (!plugin) {
- plugin = slv2_plugin_new(world, uri, bundle_uri);
- raptor_sequence_push(world->plugins, plugin);
- raptor_sequence_sort(world->plugins, slv2_plugin_compare_by_uri);
- } else {
- slv2_value_free(uri);
- }
- }
+#ifndef NDEBUG
+ if (n_plugins > 0) {
+ // Plugin results are in increasing sorted order
+ SLV2Plugin prev = raptor_sequence_get_at(world->plugins, n_plugins - 1);
+ assert(strcmp(
+ slv2_value_as_string(slv2_plugin_get_uri(prev)),
+ (const char*)librdf_uri_as_string(plugin_uri)) < 0);
}
+#endif
- plugin->world = world;
+ SLV2Plugin plugin = slv2_plugin_new(world, uri, bundle_uri);
+ raptor_sequence_push(world->plugins, plugin);
#ifdef SLV2_DYN_MANIFEST
const char* const data_uri_str = (const char*)librdf_uri_as_string(data_uri);