]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Remove redundant assertions and conditionals in move_CEnt_to_top.
authorJulian Seward <jseward@acm.org>
Tue, 13 Jul 2021 07:12:43 +0000 (09:12 +0200)
committerJulian Seward <jseward@acm.org>
Tue, 13 Jul 2021 07:12:43 +0000 (09:12 +0200)
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.

coregrind/m_debuginfo/image.c

index acb09523b634c46744f444177b1af8288e6b5bd4..ebe6dfcfe8f615553597ae2d8d6d63441cf78773 100644 (file)
@@ -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