diff mbox

[2/2,libcpp] Fix lookup of macro maps

Message ID m3vcre9uz8.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli Oct. 24, 2011, 5:10 p.m. UTC
Jason Merrill <jason@redhat.com> writes:


> I think a better fix to your binary search algorithm would be to change
>
>   mn = md;
>
> to be
>
>   mn = md + 1;
>
> since you've eliminated md as a possibility.  And then change the test to
>
>  (mn < mx).
>

Right, thanks.

Here the updated patch, bootstrapped and tested on
x86_64-unknown-linux-gnu against trunk.

From: Dodji Seketeli <dodji@redhat.com>
Date: Fri, 21 Oct 2011 16:47:07 +0200
Subject: [PATCH 2/2] Fix lookup of macro maps

	* line-map.c (linemap_macro_map_lookup): Fix logic.
---
 libcpp/line-map.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

Comments

Jason Merrill Oct. 24, 2011, 5:40 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 4af3782..97075e1 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -588,14 +588,14 @@  linemap_macro_map_lookup (struct line_maps *set, source_location line)
       mn = 0;
     }
 
-  do 
+  while (mn < mx)
     {
       md = (mx + mn) / 2;
       if (MAP_START_LOCATION (LINEMAPS_MACRO_MAP_AT (set, md)) > line)
-	mn = md;
+	mn = md + 1;
       else
 	mx = md;
-    } while (mx - mn > 1);
+    }
 
   LINEMAPS_MACRO_CACHE (set) = mx;
   result = LINEMAPS_MACRO_MAP_AT (set, LINEMAPS_MACRO_CACHE (set));