]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Minor optimizations.
authorUlrich Drepper <drepper@redhat.com>
Tue, 22 Jan 2008 06:34:31 +0000 (06:34 +0000)
committerUlrich Drepper <drepper@redhat.com>
Tue, 22 Jan 2008 06:34:31 +0000 (06:34 +0000)
libdw/ChangeLog
libdw/dwarf_child.c
libdw/dwarf_getattrs.c
libdw/dwarf_getpubnames.c
libdw/dwarf_siblingof.c
libdw/dwarf_tag.c

index 0e09213682156c957c72037d53f81066f0269c9c..d344baeff7d7e1d985aa7ccd27968e7b3528e66b 100644 (file)
@@ -1,3 +1,11 @@
+2008-01-21  Ulrich Drepper  <drepper@redhat.com>
+
+       * dwarf_child.c: Minor optimizations.
+       * dwarf_getattrs.c: Likewise.
+       * dwarf_getpubnames.c: Likewise.
+       * dwarf_siblingof.c: Likewise.
+       * dwarf_tag.c: Likewise.
+
 2008-01-18  Ulrich Drepper  <drepper@redhat.com>
 
        * dwarf_getsrclines.c (dwarf_getsrclines): Don't require exact match
index 121cd1914c5c7ee2f8f2658aadb39c93e91c70c5..0080cf9d9291a7acb9e8affd32647ad33537078b 100644 (file)
@@ -81,6 +81,7 @@ __libdw_find_attr (Dwarf_Die *die, unsigned int search_name,
     }
   if (unlikely (die->abbrev == DWARF_END_ABBREV))
     {
+    invalid_dwarf:
       __libdw_seterrno (DWARF_E_INVALID_DWARF);
       return NULL;
     }
@@ -95,10 +96,7 @@ __libdw_find_attr (Dwarf_Die *die, unsigned int search_name,
     {
       /* Are we still in bounds?  This test needs to be refined.  */
       if (unlikely (attrp + 1 >= endp))
-       {
-         __libdw_seterrno (DWARF_E_INVALID_DWARF);
-         return NULL;
-       }
+       goto invalid_dwarf;
 
       /* Get attribute name and form.
 
@@ -166,7 +164,7 @@ dwarf_child (die, result)
   if (die->abbrev != DWARF_END_ABBREV
       && (die->abbrev == NULL || die->abbrev->has_children))
     addr = __libdw_find_attr (die, INVALID, NULL, NULL);
-  if (die->abbrev == (Dwarf_Abbrev *) -1l)
+  if (unlikely (die->abbrev == (Dwarf_Abbrev *) -1l))
     return -1;
 
   /* Make sure the DIE really has children.  */
index 932c5cc1cc9ee6f147225f55406de4ec5ee57de7..42f25ca06ba427c79bb21a71d0690f5a8d24c872 100644 (file)
@@ -72,8 +72,9 @@ dwarf_getattrs (Dwarf_Die *die, int (*callback) (Dwarf_Attribute *, void *),
     /* Find the abbreviation.  */
     die->abbrev = __libdw_findabbrev (die->cu, u128);
 
-  if (die->abbrev == DWARF_END_ABBREV)
+  if (unlikely (die->abbrev == DWARF_END_ABBREV))
     {
+    invalid_dwarf:
       __libdw_seterrno (DWARF_E_INVALID_DWARF);
       return -1l;
     }
@@ -89,10 +90,7 @@ dwarf_getattrs (Dwarf_Die *die, int (*callback) (Dwarf_Attribute *, void *),
       if (unlikely (attrp
                    >= ((unsigned char *) dbg->sectiondata[IDX_debug_abbrev]->d_buf
                        + dbg->sectiondata[IDX_debug_abbrev]->d_size)))
-       {
-         __libdw_seterrno (DWARF_E_INVALID_DWARF);
-         return -1;
-       }
+       goto invalid_dwarf;
 
       /* Get attribute name and form.  */
       Dwarf_Attribute attr;
index fcf6eca4098ba292a48b805731be1721269805a6..1b054e26d9756a9a7e768442efc74472c82df3d1 100644 (file)
@@ -102,6 +102,7 @@ get_offsets (Dwarf *dbg)
       else if (unlikely (len >= DWARF3_LENGTH_MIN_ESCAPE_CODE
                         && len <= DWARF3_LENGTH_MAX_ESCAPE_CODE))
        {
+       invalid_dwarf:
          __libdw_seterrno (DWARF_E_INVALID_DWARF);
          goto err_return;
        }
@@ -116,7 +117,7 @@ get_offsets (Dwarf *dbg)
 
       /* Read the version.  It better be two for now.  */
       uint16_t version = read_2ubyte_unaligned (dbg, readp);
-      if (version != 2)
+      if (unlikely (version != 2))
        {
          __libdw_seterrno (DWARF_E_INVALID_VERSION);
          goto err_return;
@@ -129,13 +130,12 @@ get_offsets (Dwarf *dbg)
        mem[cnt].cu_offset = read_8ubyte_unaligned (dbg, readp + 2);
 
       /* Determine the size of the CU header.  */
-      if (dbg->sectiondata[IDX_debug_info] == NULL
-         || dbg->sectiondata[IDX_debug_info]->d_buf == NULL
-         || mem[cnt].cu_offset + 3 >= dbg->sectiondata[IDX_debug_info]->d_size)
-       {
-         __libdw_seterrno (DWARF_E_INVALID_DWARF);
-         goto err_return;
-       }
+      if (unlikely (dbg->sectiondata[IDX_debug_info] == NULL
+                   || dbg->sectiondata[IDX_debug_info]->d_buf == NULL
+                   || (mem[cnt].cu_offset + 3
+                       >= dbg->sectiondata[IDX_debug_info]->d_size)))
+       goto invalid_dwarf;
+
       unsigned char *infop
        = ((unsigned char *) dbg->sectiondata[IDX_debug_info]->d_buf
           + mem[cnt].cu_offset);
@@ -173,7 +173,7 @@ dwarf_getpubnames (dbg, callback, arg, offset)
   if (dbg == NULL)
     return -1l;
 
-  if (offset < 0)
+  if (unlikely (offset < 0))
     {
       __libdw_seterrno (DWARF_E_INVALID_OFFSET);
       return -1l;
@@ -187,7 +187,7 @@ dwarf_getpubnames (dbg, callback, arg, offset)
     return 0;
 
   /* If necessary read the set information.  */
-  if (dbg->pubnames_nsets == 0 && get_offsets (dbg) != 0)
+  if (dbg->pubnames_nsets == 0 && unlikely (get_offsets (dbg) != 0))
     return -1l;
 
   /* Find the place where to start.  */
index 7347013f396a039fcd7c6b61c577b5c148b959ce..0d42717514cab8851a7c9216a2b661d82ccc73ce 100644 (file)
@@ -98,7 +98,7 @@ dwarf_siblingof (die, result)
        {
          Dwarf_Off offset;
          sibattr.valp = addr;
-         if (__libdw_formref (&sibattr, &offset) != 0)
+         if (unlikely (__libdw_formref (&sibattr, &offset) != 0))
            /* Something went wrong.  */
            return -1;
 
index 5280ab24af1814aee46410c49260e08f09f349a7..15183d2db04db2a93aef8fa19819359b37798a1c 100644 (file)
@@ -106,7 +106,7 @@ dwarf_tag (die)
       die->abbrev = __libdw_findabbrev (die->cu, u128);
     }
 
-  if (die->abbrev == DWARF_END_ABBREV)
+  if (unlikely (die->abbrev == DWARF_END_ABBREV))
     {
       __libdw_seterrno (DWARF_E_INVALID_DWARF);
       return DW_TAG_invalid;