From patchwork Mon Oct 16 03:04:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23585 Received: (qmail 98666 invoked by alias); 16 Oct 2017 03:04:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 98583 invoked by uid 89); 16 Oct 2017 03:04:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Oct 2017 03:04:38 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy10.mail.unifiedlayer.com (Postfix) with ESMTP id 31DBD1405F3 for ; Sun, 15 Oct 2017 21:04:37 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id N34Z1w00c2f2jeq0134cMy; Sun, 15 Oct 2017 21:04:37 -0600 X-Authority-Analysis: v=2.2 cv=H76r+6Qi c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=02M-m0pO-4AA:10 a=zstS-IiYAAAA:8 a=oRBI9hJhXb_fZYg5sqgA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 184-96-33-178.hlrn.qwest.net ([184.96.33.178]:40598 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1e3vhh-003iPW-CR; Sun, 15 Oct 2017 21:04:33 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/6] Use std::vector in end_symtab_get_static_block Date: Sun, 15 Oct 2017 21:04:22 -0600 Message-Id: <20171016030427.21349-2-tom@tromey.com> In-Reply-To: <20171016030427.21349-1-tom@tromey.com> References: <20171016030427.21349-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1e3vhh-003iPW-CR X-Source-Sender: 184-96-33-178.hlrn.qwest.net (bapiya.localdomain) [184.96.33.178]:40598 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes Change end_symtab_get_static_block to use std::vector. This removes a cleanup. ChangeLog 2017-10-15 Tom Tromey * buildsym.c (block_compar): Remove. (end_symtab_get_static_block): Use std::vector. --- gdb/ChangeLog | 5 +++++ gdb/buildsym.c | 38 ++++++++++---------------------------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index cbad027d0c..c3cfc37cd6 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -86,6 +86,7 @@ #include "cp-support.h" #include "dictionary.h" #include "addrmap.h" +#include /* Ask buildsym.h to define the vars it normally declares `extern'. */ #define EXTERN @@ -1165,19 +1166,6 @@ watch_main_source_file_lossage (void) } } -/* Helper function for qsort. Parameters are `struct block *' pointers, - function sorts them in descending order by their BLOCK_START. */ - -static int -block_compar (const void *ap, const void *bp) -{ - const struct block *a = *(const struct block **) ap; - const struct block *b = *(const struct block **) bp; - - return ((BLOCK_START (b) > BLOCK_START (a)) - - (BLOCK_START (b) < BLOCK_START (a))); -} - /* Reset state after a successful building of a symtab. This exists because dbxread.c and xcoffread.c can call start_symtab+end_symtab multiple times after one call to buildsym_init, @@ -1254,28 +1242,22 @@ end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required) if ((objfile->flags & OBJF_REORDERED) && pending_blocks) { - unsigned count = 0; struct pending_block *pb; - struct block **barray, **bp; - struct cleanup *back_to; - - for (pb = pending_blocks; pb != NULL; pb = pb->next) - count++; - barray = XNEWVEC (struct block *, count); - back_to = make_cleanup (xfree, barray); + std::vector barray; - bp = barray; for (pb = pending_blocks; pb != NULL; pb = pb->next) - *bp++ = pb->block; + barray.push_back (pb->block); - qsort (barray, count, sizeof (*barray), block_compar); + std::sort (barray.begin (), barray.end (), + [] (const block *a, const block *b) + { + return BLOCK_START (a) > BLOCK_START (b); + }); - bp = barray; + int i = 0; for (pb = pending_blocks; pb != NULL; pb = pb->next) - pb->block = *bp++; - - do_cleanups (back_to); + pb->block = barray[i++]; } /* Cleanup any undefined types that have been left hanging around