diff options
Diffstat (limited to 'src/document-subset.cpp')
| -rw-r--r-- | src/document-subset.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/document-subset.cpp b/src/document-subset.cpp index 217176f4e..4e7e9f694 100644 --- a/src/document-subset.cpp +++ b/src/document-subset.cpp @@ -57,17 +57,32 @@ struct DocumentSubset::Relations : public GC::Managed<GC::ATOMIC>, } else { Siblings::const_iterator first=children.begin(); Siblings::const_iterator last=children.end() - 1; - while ( first != last ) { - Siblings::const_iterator mid=first + ( last - first + 1 ) / 2; - int pos=sp_object_compare_position(*mid, obj); + if ( children.size() == 1 ) { + int pos = sp_object_compare_position(*first, obj); if ( pos < 0 ) { - first = mid; + // All good. } else if ( pos > 0 ) { - last = mid; + last++; } 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(); + } + } } + return last - children.begin(); } } |
