X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fdocument-subset.cpp;h=4ef547320a292cec1dca48c9b1a5161107dbee69;hb=9b6c50478ce8c03e775b9e77204377d4a8cc2b41;hp=4e7e9f694f6a49e00fe995aa6aebe263c8572fa0;hpb=0832343fd7f087d3b718bc86f2cf74014e56b582;p=inkscape.git diff --git a/src/document-subset.cpp b/src/document-subset.cpp index 4e7e9f694..4ef547320 100644 --- a/src/document-subset.cpp +++ b/src/document-subset.cpp @@ -57,29 +57,28 @@ struct DocumentSubset::Relations : public GC::Managed, } else { Siblings::const_iterator first=children.begin(); Siblings::const_iterator last=children.end() - 1; - if ( children.size() == 1 ) { - int pos = sp_object_compare_position(*first, obj); + + while ( first != last ) { + Siblings::const_iterator mid = first + ( last - first + 1 ) / 2; + int pos = sp_object_compare_position(*mid, obj); if ( pos < 0 ) { - // All good. + first = mid; } else if ( pos > 0 ) { - last++; + if ( last == mid ) { + last = mid - 1; // already at the top limit + } else { + last = mid; + } } else { g_assert_not_reached(); } - } else { - while ( first != last ) { - Siblings::const_iterator mid=first + ( last - first + 1 ) / 2; - int pos=sp_object_compare_position(*mid, obj); - if ( pos < 0 ) { - first = mid; - } else if ( pos > 0 ) { - if ( last == mid ) { - break; - } - last = mid; - } else { - g_assert_not_reached(); - } + } + + if ( first == last ) { + // compare to the single possiblity left + int pos = sp_object_compare_position(*last, obj); + if ( pos < 0 ) { + last++; } }