From 8991873658747287b86eb477442508a9a3014e5f Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 14 May 2006 07:21:09 +0000 Subject: Corrected base structure and avoiding infinite loop. (bzr r833) --- src/document-subset.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/document-subset.cpp') 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, } 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(); } } -- cgit v1.2.3