Changeset 2081

Show
Ignore:
Timestamp:
06/03/09 12:38:56 (9 months ago)
Author:
drobilla
Message:

Avoid sorting/searching during plugin discovery if results happen to be in order (without actually requesting this with ORDER BY, which can be slower).
This should perform relatively well with any RDF backend, which tend to return sorted results anyway as an implementation detail (and redland with trees does).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/slv2/src/world.c

    r2058 r2081  
    518518 
    519519        // Find all plugins and associated data files 
    520         unsigned char* query_string = (unsigned char*) 
     520        const unsigned char* query_string = (unsigned char*) 
    521521                "PREFIX : <http://lv2plug.in/ns/lv2core#>\n" 
    522522                "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" 
     
    524524                "SELECT DISTINCT ?plugin ?data ?bundle\n" 
    525525                "WHERE { ?plugin a :Plugin; slv2:bundleURI ?bundle; rdfs:seeAlso ?data }\n"; 
    526                 //"ORDER BY ?plugin\n"; 
    527526 
    528527        librdf_query* q = librdf_new_query(world->world, "sparql", 
     
    532531 
    533532        while (!librdf_query_results_finished(results)) { 
    534  
    535533                librdf_node* plugin_node = librdf_query_results_get_binding_value(results, 0); 
    536534                librdf_uri*  plugin_uri  = librdf_node_get_uri(plugin_node); 
     
    540538                librdf_uri*  bundle_uri  = librdf_node_get_uri(bundle_node); 
    541539 
    542                 assert(plugin_uri); 
    543                 assert(data_uri); 
    544  
    545                 SLV2Value   uri    = slv2_value_new_librdf_uri(world, plugin_uri); 
    546                 SLV2Plugin  plugin = slv2_plugins_get_by_uri(world->plugins, uri); 
    547  
    548                 // Create a new SLV2Plugin 
    549                 if (!plugin) { 
    550                         plugin = slv2_plugin_new(world, uri, bundle_uri); 
    551                         raptor_sequence_push(world->plugins, plugin); 
    552                         // FIXME: Slow!  ORDER BY broken in certain versions of redland? 
    553                         raptor_sequence_sort(world->plugins, slv2_plugin_compare_by_uri); 
    554                 } else { 
    555                         slv2_value_free(uri); 
     540                if (plugin_uri && data_uri) { 
     541                        SLV2Plugin plugin = NULL; 
     542 
     543                        // Check if this is another match for the last plugin (avoid search) 
     544                        const unsigned n_plugins = raptor_sequence_size(world->plugins); 
     545                        if (n_plugins >= 1) { 
     546                                SLV2Plugin prev = raptor_sequence_get_at(world->plugins, n_plugins - 1); 
     547                                if (librdf_uri_equals(plugin_uri, prev->plugin_uri->val.uri_val)) 
     548                                        plugin = prev; 
     549                        } 
     550 
     551                        SLV2Value uri = slv2_value_new_librdf_uri(world, plugin_uri); 
     552 
     553                        // If this plugin differs from the last, append a new SLV2Plugin 
     554                        if (!plugin) { 
     555                                if (n_plugins == 0) { 
     556                                        plugin = slv2_plugin_new(world, uri, bundle_uri); 
     557                                        raptor_sequence_push(world->plugins, plugin); 
     558                                } else { 
     559                                        SLV2Plugin first = raptor_sequence_get_at(world->plugins, 0); 
     560                                        SLV2Plugin prev  = raptor_sequence_get_at(world->plugins, n_plugins - 1); 
     561 
     562                                        // If the URI is > the last in the list, just append (avoid sort) 
     563                                        if (strcmp( 
     564                                                        slv2_value_as_string(slv2_plugin_get_uri(prev)), 
     565                                                        librdf_uri_as_string(plugin_uri)) < 0) { 
     566                                                plugin = slv2_plugin_new(world, uri, bundle_uri); 
     567                                                raptor_sequence_push(world->plugins, plugin); 
     568 
     569                                        // If the URI is < the first in the list, just prepend (avoid sort) 
     570                                        } else if (strcmp( 
     571                                                        slv2_value_as_string(slv2_plugin_get_uri(first)), 
     572                                                        librdf_uri_as_string(plugin_uri)) > 0) { 
     573                                                plugin = slv2_plugin_new(world, uri, bundle_uri); 
     574                                                raptor_sequence_shift(world->plugins, plugin); 
     575 
     576                                        // Otherwise the query engine is giving us unsorted results :/ 
     577                                        } else { 
     578                                                plugin = slv2_plugins_get_by_uri(world->plugins, uri); 
     579                                                if (!plugin) { 
     580                                                        plugin = slv2_plugin_new(world, uri, bundle_uri); 
     581                                                        raptor_sequence_push(world->plugins, plugin); 
     582                                                        raptor_sequence_sort(world->plugins, slv2_plugin_compare_by_uri); 
     583                                                } 
     584                                        } 
     585                                } 
     586                        } 
     587 
     588                        plugin->world = world; 
     589 
     590                        // FIXME: check for duplicates 
     591                        raptor_sequence_push(plugin->data_uris, 
     592                                        slv2_value_new_librdf_uri(plugin->world, data_uri)); 
    556593                } 
    557  
    558                 plugin->world = world; 
    559  
    560                 // FIXME: check for duplicates 
    561                 raptor_sequence_push(plugin->data_uris, 
    562                                 slv2_value_new_librdf_uri(plugin->world, data_uri)); 
    563594 
    564595                librdf_free_node(plugin_node);