|
From: Julian S. <se...@so...> - 2021-07-13 07:15:13
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=a2becd59ae1d1ef6e774549b203d5c158fa20666 commit a2becd59ae1d1ef6e774549b203d5c158fa20666 Author: Julian Seward <js...@ac...> Date: Tue Jul 13 09:12:43 2021 +0200 Remove redundant assertions and conditionals in move_CEnt_to_top. move_CEnt_to_top is on the hot path when reading large amounts of debug info, especially Dwarf inlined-function info. It shows up in 'perf' profiles. This commit removes assertions which are asserted elsewhere, and tries to avoid a couple of conditional branches. Diff: --- coregrind/m_debuginfo/image.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/coregrind/m_debuginfo/image.c b/coregrind/m_debuginfo/image.c index acb09523b6..ebe6dfcfe8 100644 --- a/coregrind/m_debuginfo/image.c +++ b/coregrind/m_debuginfo/image.c @@ -523,14 +523,24 @@ static void realloc_CEnt ( DiImage* img, UInt entNo, SizeT szB, Bool fromC ) to make space. */ static void move_CEnt_to_top ( DiImage* img, UInt entNo ) { - vg_assert(img->ces_used <= CACHE_N_ENTRIES); - vg_assert(entNo > 0 && entNo < img->ces_used); - CEnt* tmp = img->ces[entNo]; - while (entNo > 0) { + vg_assert(entNo < img->ces_used); + if (LIKELY(entNo == 1)) { + CEnt* tmp = img->ces[1]; + img->ces[entNo] = img->ces[0]; + img->ces[0] = tmp; + } else { + vg_assert(entNo > 1); // a.k.a. >= 2 + CEnt* tmp = img->ces[entNo]; img->ces[entNo] = img->ces[entNo-1]; entNo--; + img->ces[entNo] = img->ces[entNo-1]; + entNo--; + while (entNo > 0) { + img->ces[entNo] = img->ces[entNo-1]; + entNo--; + } + img->ces[0] = tmp; } - img->ces[0] = tmp; } /* Set the given entry so that it has a chunk of the file containing |