From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 9FD3C385842C; Fri, 27 Jan 2023 21:13:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FD3C385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674854019; bh=EkyezfPo07MOn2Ygnj8Cnv7Kv2DxsuTFTbJmSb2PQr0=; h=From:To:Subject:Date:From; b=W7eM0lppOs6hrRnSfj+ao+C1SSmZY63cVhpwgc4dinonDc3M9OHO8B9ivlo4xw6sV 1OX1343QJCkePGPaqcpOW8MMQRamcKQWXqAhQ7k+nmAabX/8zKQBej1vlyWuMKSRGt eEgjRd7XHE9NyTcvUe0nlEmtBsaSIDeP/n1L8uFk= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] More const-correctness in cooked indexer X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: d9195131530370f56e78a2b084928c11da536d9e X-Git-Newrev: 35e1763185224b2bf634e19cdfd06dab0ba914e3 Message-Id: <20230127211339.9FD3C385842C@sourceware.org> Date: Fri, 27 Jan 2023 21:13:39 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D35e176318522= 4b2bf634e19cdfd06dab0ba914e3 commit 35e1763185224b2bf634e19cdfd06dab0ba914e3 Author: Tom Tromey Date: Fri Jan 27 09:20:43 2023 -0700 More const-correctness in cooked indexer =20 I noticed that iterating over the index yields non-const cooked_index_entry objects. However, after finalization, they should not be modified. This patch enforces this by adding const where needed. =20 v2 makes the find, all_entries, and wait methods const as well. Diff: --- gdb/dwarf2/cooked-index.c | 8 ++++---- gdb/dwarf2/cooked-index.h | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 09b3fd70b26..1a568e6aae7 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -355,11 +355,11 @@ cooked_index::do_finalize () /* See cooked-index.h. */ =20 cooked_index::range -cooked_index::find (const std::string &name, bool completing) +cooked_index::find (const std::string &name, bool completing) const { wait (); =20 - auto lower =3D std::lower_bound (m_entries.begin (), m_entries.end (), n= ame, + auto lower =3D std::lower_bound (m_entries.cbegin (), m_entries.cend (),= name, [=3D] (const cooked_index_entry *entry, const std::string &n) { @@ -367,7 +367,7 @@ cooked_index::find (const std::string &name, bool compl= eting) completing); }); =20 - auto upper =3D std::upper_bound (m_entries.begin (), m_entries.end (), n= ame, + auto upper =3D std::upper_bound (m_entries.cbegin (), m_entries.cend (),= name, [=3D] (const std::string &n, const cooked_index_entry *entry) { @@ -413,7 +413,7 @@ cooked_index_vector::get_addrmaps () /* See cooked-index.h. */ =20 cooked_index_vector::range -cooked_index_vector::find (const std::string &name, bool completing) +cooked_index_vector::find (const std::string &name, bool completing) const { std::vector result_range; result_range.reserve (m_vector.size ()); diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 55eaf9955ab..e12376cdf98 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -217,7 +217,7 @@ public: void finalize (); =20 /* Wait for this index's finalization to be complete. */ - void wait () + void wait () const { m_future.wait (); } @@ -225,19 +225,20 @@ public: friend class cooked_index_vector; =20 /* A simple range over part of m_entries. */ - typedef iterator_range::iterator> rang= e; + typedef iterator_range::const_iterator> + range; =20 /* Return a range of all the entries. */ - range all_entries () + range all_entries () const { wait (); - return { m_entries.begin (), m_entries.end () }; + return { m_entries.cbegin (), m_entries.cend () }; } =20 /* Look up an entry by name. Returns a range of all matching results. If COMPLETING is true, then a larger range, suitable for completion, will be returned. */ - range find (const std::string &name, bool completing); + range find (const std::string &name, bool completing) const; =20 private: =20 @@ -317,7 +318,7 @@ public: =20 /* Wait until the finalization of the entire cooked_index_vector is done. */ - void wait () + void wait () const { for (auto &item : m_vector) item->wait (); @@ -340,10 +341,10 @@ public: /* Look up an entry by name. Returns a range of all matching results. If COMPLETING is true, then a larger range, suitable for completion, will be returned. */ - range find (const std::string &name, bool completing); + range find (const std::string &name, bool completing) const; =20 /* Return a range of all the entries. */ - range all_entries () + range all_entries () const { std::vector result_range; result_range.reserve (m_vector.size ());