public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] More const-correctness in cooked indexer
@ 2023-01-27 16:22 Tom Tromey
  2023-01-27 20:11 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-01-27 16:22 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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.
---
 gdb/dwarf2/cooked-index.c | 4 ++--
 gdb/dwarf2/cooked-index.h | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index 09b3fd70b26..bc4fe20aa2a 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -359,7 +359,7 @@ cooked_index::find (const std::string &name, bool completing)
 {
   wait ();
 
-  auto lower = std::lower_bound (m_entries.begin (), m_entries.end (), name,
+  auto lower = std::lower_bound (m_entries.cbegin (), m_entries.cend (), name,
 				 [=] (const cooked_index_entry *entry,
 				      const std::string &n)
   {
@@ -367,7 +367,7 @@ cooked_index::find (const std::string &name, bool completing)
 					completing);
   });
 
-  auto upper = std::upper_bound (m_entries.begin (), m_entries.end (), name,
+  auto upper = std::upper_bound (m_entries.cbegin (), m_entries.cend (), name,
 				 [=] (const std::string &n,
 				      const cooked_index_entry *entry)
   {
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 55eaf9955ab..cb6795b97a7 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -225,13 +225,14 @@ class cooked_index
   friend class cooked_index_vector;
 
   /* A simple range over part of m_entries.  */
-  typedef iterator_range<std::vector<cooked_index_entry *>::iterator> range;
+  typedef iterator_range<std::vector<cooked_index_entry *>::const_iterator>
+       range;
 
   /* Return a range of all the entries.  */
   range all_entries ()
   {
     wait ();
-    return { m_entries.begin (), m_entries.end () };
+    return { m_entries.cbegin (), m_entries.cend () };
   }
 
   /* Look up an entry by name.  Returns a range of all matching
-- 
2.38.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-27 21:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27 16:22 [PATCH] More const-correctness in cooked indexer Tom Tromey
2023-01-27 20:11 ` Simon Marchi
2023-01-27 21:11   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).