From patchwork Mon Oct 24 17:10:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 121385 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C9C271007D1 for ; Tue, 25 Oct 2011 04:10:31 +1100 (EST) Received: (qmail 7302 invoked by alias); 24 Oct 2011 17:10:27 -0000 Received: (qmail 7292 invoked by uid 22791); 24 Oct 2011 17:10:25 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 24 Oct 2011 17:10:06 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9OHA56Q029030 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 24 Oct 2011 13:10:05 -0400 Received: from localhost (ovpn-113-61.phx2.redhat.com [10.3.113.61]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9OHA44Z029319 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 24 Oct 2011 13:10:05 -0400 Received: by localhost (Postfix, from userid 500) id 7C0DE29C129; Mon, 24 Oct 2011 19:10:03 +0200 (CEST) From: Dodji Seketeli To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, tromey@redhat.com Subject: Re: [PATCH 2/2, libcpp] Fix lookup of macro maps References: <1319240276-26273-1-git-send-email-dodji@redhat.com> <1319240276-26273-3-git-send-email-dodji@redhat.com> <4EA2D6A4.7080206@redhat.com> X-URL: http://www.redhat.com Date: Mon, 24 Oct 2011 19:10:03 +0200 In-Reply-To: <4EA2D6A4.7080206@redhat.com> (Jason Merrill's message of "Sat, 22 Oct 2011 10:43:48 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Jason Merrill 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 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(-) 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));