]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/dwarf: use std::equal_range in cooked_index_shard::find
authorSimon Marchi <simon.marchi@polymtl.ca>
Mon, 24 Mar 2025 20:20:28 +0000 (16:20 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 25 Mar 2025 15:44:37 +0000 (11:44 -0400)
commitebfdb1089bc84fafa7001e7ff2e9c389c11437a6
treed719cde64fafb242c9452f549d6191d1d5c0b16b
parent8cbf7d2a4748b37d70323f45a378aee8a9a96f8a
gdb/dwarf: use std::equal_range in cooked_index_shard::find

Looking at `cooked_index_shard::find`, I thought that we could make a
small optimization: when finding the upper bound, we already know the
lower bound.  And we know that the upper bound is >= the lower bound.
So we could pass `lower` as the first argument of the `std::upper_bound`
call to cut the part of the search space that is below `lower`.

It then occured to me that what we do is basically what
`std::equal_range` is for, so why not use it.  Implementations of
`std::equal_range` are likely do to things as efficiently as possible.

Unfortunately, because `cooked_index_entry::compare` is sensitive to the
order of its parameters, we need to provide two different comparison
functions (just like we do know, to the lower_bound and upper_bound
calls).  But I think that the use of equal_range makes it clear what the
intent of the code is.

Regression tested using the various DWARF target boards on Debian 12.

Change-Id: Idfad812fb9abae1b942d81ad9976aeed7c2cf762
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/cooked-index.c