More efficient AbbrevDecl handling (#212)
authorAnders Dellien <anders@andersdellien.se>
Mon, 24 Dec 2018 16:56:52 +0000 (17:56 +0100)
committerEli Bendersky <eliben@users.noreply.github.com>
Mon, 24 Dec 2018 16:56:52 +0000 (08:56 -0800)
Create all the AbbrevDecl objects during parsing and later return
references to them - this gives a small performance gain.

elftools/dwarf/abbrevtable.py

index 36f6d2a0973b16ca2cc934e8fd9438ef6da2a68e..6d29d5cfe8ca3fc9a69efe295c50453e0f4ced03 100644 (file)
@@ -33,7 +33,7 @@ class AbbrevTable(object):
         """ Get the AbbrevDecl for a given code. Raise KeyError if no
             declaration for this code exists.
         """
-        return AbbrevDecl(code, self._abbrev_map[code])
+        return self._abbrev_map[code]
 
     def _parse_abbrev_table(self):
         """ Parse the abbrev table from the stream
@@ -49,7 +49,7 @@ class AbbrevTable(object):
             declaration = struct_parse(
                 struct=self.structs.Dwarf_abbrev_declaration,
                 stream=self.stream)
-            map[decl_code] = declaration
+            map[decl_code] = AbbrevDecl(decl_code, declaration)
         return map