From: Julian Seward Date: Tue, 13 Jul 2021 07:12:43 +0000 (+0200) Subject: Remove redundant assertions and conditionals in move_CEnt_to_top. X-Git-Tag: VALGRIND_3_18_0~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2becd59ae1d1ef6e774549b203d5c158fa20666;p=thirdparty%2Fvalgrind.git 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 --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