[arch-projects] [namcap] [PATCH] Use section.iter_tags('type') as applicable
Emil Velikov
emil.l.velikov at gmail.com
Tue Jan 5 01:40:34 UTC 2021
This produces shorter and faster code. The speed-up depends greatly on
the workload - so here are some examples:
File: mesa-18.3.2-1-x86_64.pkg.tar.xz from [1]
Before:
1.66s user 0.15s system 100% cpu 1.814 total
1.61s user 0.21s system 100% cpu 1.820 total
1.69s user 0.15s system 100% cpu 1.832 total
After:
1.62s user 0.17s system 100% cpu 1.782 total
1.66s user 0.14s system 100% cpu 1.800 total
1.63s user 0.15s system 100% cpu 1.781 total
File: mesa-18.3.2-1-x86_64.pkg.tar.xz renamed to foo.bar
Note: due to the rename, the build-in python extractor is used.
Before:
687.76s user 2.19s system 99% cpu 11:30.68 total
After:
390.73s user 1.37s system 99% cpu 6:32.72 total
[1]
https://archive.archlinux.org/packages/m/mesa/mesa-18.3.2-1-x86_64.pkg.tar.xz
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
Namcap/rules/elffiles.py | 7 +++----
Namcap/rules/rpath.py | 4 +---
Namcap/rules/runpath.py | 4 +---
Namcap/rules/sodepends.py | 4 +---
Namcap/tests/package/test_sodepends.py | 5 ++---
5 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/Namcap/rules/elffiles.py b/Namcap/rules/elffiles.py
index 4ad1e66..212f4c8 100644
--- a/Namcap/rules/elffiles.py
+++ b/Namcap/rules/elffiles.py
@@ -87,9 +87,8 @@ class ELFTextRelocationRule(TarballRule):
for section in elffile.iter_sections():
if not isinstance(section, DynamicSection):
continue
- for tag in section.iter_tags():
- if tag.entry.d_tag == 'DT_TEXTREL':
- files_with_textrel.append(entry.name)
+ for tag in section.iter_tags('DT_TEXTREL'):
+ files_with_textrel.append(entry.name)
if files_with_textrel:
self.warnings = [("elffile-with-textrel %s", i)
@@ -218,7 +217,7 @@ class NoPIERule(TarballRule):
for section in elffile.iter_sections():
if not isinstance(section, DynamicSection):
continue
- if any(tag.entry.d_tag == 'DT_DEBUG' for tag in section.iter_tags()):
+ for tag in section.iter_tags('DT_DEBUG'):
return True
return False
diff --git a/Namcap/rules/rpath.py b/Namcap/rules/rpath.py
index 4da040c..cb5a922 100644
--- a/Namcap/rules/rpath.py
+++ b/Namcap/rules/rpath.py
@@ -32,9 +32,7 @@ def get_rpaths(fileobj):
for section in elffile.iter_sections():
if not isinstance(section, DynamicSection):
continue
- for tag in section.iter_tags():
- if tag.entry.d_tag != 'DT_RPATH':
- continue
+ for tag in section.iter_tags('DT_RPATH'):
rpaths = tag.rpath
rpaths = rpaths.split(':')
for path in rpaths:
diff --git a/Namcap/rules/runpath.py b/Namcap/rules/runpath.py
index 00874be..22c42f1 100644
--- a/Namcap/rules/runpath.py
+++ b/Namcap/rules/runpath.py
@@ -32,9 +32,7 @@ def get_runpaths(fileobj):
for section in elffile.iter_sections():
if not isinstance(section, DynamicSection):
continue
- for tag in section.iter_tags():
- if tag.entry.d_tag != 'DT_RUNPATH':
- continue
+ for tag in section.iter_tags('DT_RUNPATH'):
for path in tag.runpath.split(':'):
yield path
diff --git a/Namcap/rules/sodepends.py b/Namcap/rules/sodepends.py
index 2f061bb..c565109 100644
--- a/Namcap/rules/sodepends.py
+++ b/Namcap/rules/sodepends.py
@@ -52,10 +52,8 @@ def scanlibs(fileobj, filename, custom_libs):
for section in elffile.iter_sections():
if not isinstance(section, DynamicSection):
continue
- for tag in section.iter_tags():
+ for tag in section.iter_tags('DT_NEEDED'):
# DT_NEEDED means shared library
- if tag.entry.d_tag != 'DT_NEEDED':
- continue
bitsize = elffile.elfclass
architecture = {32:'i686', 64:'x86-64'}[bitsize]
libname = tag.needed
diff --git a/Namcap/tests/package/test_sodepends.py b/Namcap/tests/package/test_sodepends.py
index d5537ac..fe622ea 100644
--- a/Namcap/tests/package/test_sodepends.py
+++ b/Namcap/tests/package/test_sodepends.py
@@ -31,9 +31,8 @@ def get_soname(filename):
for section in alpm.iter_sections():
if not isinstance(section, DynamicSection):
continue
- for tag in section.iter_tags():
- if tag.entry.d_tag == 'DT_SONAME':
- return tag.soname
+ for tag in section.iter_tags('DT_SONAME'):
+ return tag.soname
class SoDependsTest(MakepkgTest):
pkgbuild = """
--
2.30.0
More information about the arch-projects
mailing list