From: Eli Bendersky Date: Wed, 17 Aug 2022 12:46:40 +0000 (-0700) Subject: Minor stylistic fixes following up the previous commit X-Git-Tag: v0.30~22 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=13bf0786fca87f89ff7046549a413c23b5f38ca9;p=pyelftools.git Minor stylistic fixes following up the previous commit --- diff --git a/elftools/dwarf/structs.py b/elftools/dwarf/structs.py index e0a67c4..fe68d43 100644 --- a/elftools/dwarf/structs.py +++ b/elftools/dwarf/structs.py @@ -77,7 +77,10 @@ class DWARFStructs(object): See also the documentation of public methods. """ - __StructsCache = {} + # Cache for structs instances based on creation parameters. Structs + # initialization is expensive and we don't won't to repeat it + # unnecessarily. + _structs_cache = {} def __new__(cls, little_endian, dwarf_format, address_size, dwarf_version=2): """ dwarf_version: @@ -95,8 +98,8 @@ class DWARFStructs(object): """ key = (little_endian, dwarf_format, address_size, dwarf_version) - if key in cls.__StructsCache: - return cls.__StructsCache[key] + if key in cls._structs_cache: + return cls._structs_cache[key] self = super().__new__(cls) assert dwarf_format == 32 or dwarf_format == 64 @@ -106,7 +109,7 @@ class DWARFStructs(object): self.address_size = address_size self.dwarf_version = dwarf_version self._create_structs() - cls.__StructsCache[key] = self + cls._structs_cache[key] = self return self def initial_length_field_size(self): @@ -273,7 +276,7 @@ class DWARFStructs(object): # New forms in DWARFv5 DW_FORM_loclistx=self.Dwarf_uleb128(''), - DW_FORM_rnglistx=self.Dwarf_uleb128('') + DW_FORM_rnglistx=self.Dwarf_uleb128('') ) def _create_aranges_header(self): diff --git a/elftools/elf/elffile.py b/elftools/elf/elffile.py index bddb77e..59f657b 100644 --- a/elftools/elf/elffile.py +++ b/elftools/elf/elffile.py @@ -626,7 +626,7 @@ class ELFFile(object): """ if self._section_header_stringtable is None: raise ELFParseError("String Table not found") - + name_offset = section_header['sh_name'] return self._section_header_stringtable.get_string(name_offset)