| 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)); |