diff options
author | David Robillard <d@drobilla.net> | 2011-04-28 00:18:06 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-04-28 00:18:06 +0000 |
commit | fdf456d59ab52f2f49c1bbb53c565a512923686c (patch) | |
tree | 8dc0ad29e6fe75423976aab68b4f3a2baa0da659 | |
parent | 237c2c01fe1efe52859bb21193938deb7a2b93ac (diff) | |
download | sord-fdf456d59ab52f2f49c1bbb53c565a512923686c.tar.gz sord-fdf456d59ab52f2f49c1bbb53c565a512923686c.tar.bz2 sord-fdf456d59ab52f2f49c1bbb53c565a512923686c.zip |
Remove redundant search in sord_add.
git-svn-id: http://svn.drobilla.net/sord/trunk@95 3d64ff67-21c5-427c-a301-fe4f08042e5a
-rw-r--r-- | src/sord.c | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -664,11 +664,8 @@ index_search(SordModel* sord, GSequence* db, const SordQuad search_key) } static inline GSequenceIter* -index_lower_bound(SordModel* sord, GSequence* db, const SordQuad search_key) +index_lower_bound_iter(SordModel* sord, GSequenceIter* i, const SordQuad search_key) { - GSequenceIter* i = g_sequence_search( - db, (void*)search_key, sord_quad_compare, sord); - /* i is now at the position where search_key would be inserted, but this is not necessarily a match, and we need the leftmost... */ @@ -708,6 +705,14 @@ index_lower_bound(SordModel* sord, GSequence* db, const SordQuad search_key) return i; } +static inline GSequenceIter* +index_lower_bound(SordModel* sord, GSequence* db, const SordQuad search_key) +{ + GSequenceIter* i = g_sequence_search( + db, (void*)search_key, sord_quad_compare, sord); + return index_lower_bound_iter(sord, i, search_key); +} + SordIter* sord_find(SordModel* sord, const SordQuad pat) { @@ -968,9 +973,10 @@ sord_add_to_index(SordModel* sord, const SordQuad tup, SordOrder order) const SordQuad key = { tup[ordering[0]], tup[ordering[1]], tup[ordering[2]], tup[ordering[3]] }; - GSequenceIter* const cur = index_search(sord, sord->indices[order], key); - if (!g_sequence_iter_is_end(cur) - && !sord_quad_compare(g_sequence_get(cur), key, sord)) { + GSequenceIter* const cur = index_search(sord, sord->indices[order], key); + GSequenceIter* const match = index_lower_bound_iter(sord, cur, key); + if (!g_sequence_iter_is_end(match) + && !sord_quad_compare(g_sequence_get(match), key, sord)) { return false; // Quad already stored in this index } @@ -991,14 +997,6 @@ sord_add(SordModel* sord, const SordQuad tup) return false; } - // FIXME: Remove double search - SordQuad pat = { tup[0], tup[1], tup[2], tup[3] }; - SordIter* existing = sord_find(sord, pat); - if (existing) { - sord_iter_free(existing); - return false; - } - for (unsigned i = 0; i < NUM_ORDERS; ++i) { if (sord->indices[i]) { if (!sord_add_to_index(sord, tup, i)) { |