]> git.ipfire.org Git - oddments/collecty.git/commitdiff
re: Avoid pre-compiling regular expressions
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 20 Sep 2020 14:10:13 +0000 (14:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 20 Sep 2020 14:14:29 +0000 (14:14 +0000)
Python has a cache for these

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/collecty/plugins/base.py
src/collecty/plugins/contextswitches.py
src/collecty/plugins/cpufreq.py
src/collecty/plugins/disk.py
src/collecty/plugins/interrupts.py

index c85e315958773f61c20762e3ce57f3f7b0fc8bab..80647cdb30f447a0c001d4c7dc935cfcb0678b9d 100644 (file)
@@ -35,7 +35,7 @@ from .. import util
 from ..constants import *
 from ..i18n import _
 
-DEF_MATCH = re.compile(r"C?DEF:([A-Za-z0-9_]+)=")
+DEF_MATCH = r"C?DEF:([A-Za-z0-9_]+)="
 
 class Environment(object):
        """
index c1299aa812baa34839fdf511a584b8c6b01b91e6..a7f7840f9fcd64c8373a4d01d40e6f30a9ff9e24 100644 (file)
@@ -67,7 +67,7 @@ class ContextSwitchesObject(base.Object):
                return "default"
 
        def collect(self):
-               expr = re.compile(r"^ctxt (\d+)$")
+               expr = r"^ctxt (\d+)$"
 
                with open("/proc/stat") as f:
                        for line in f.readlines():
index e6b86474555f41701cc459e6e08c845e2612c69f..c6108918d707bcbaad1ff9298a97631ffd2c9358 100644 (file)
@@ -126,14 +126,12 @@ class CPUFreqPlugin(base.Plugin):
 
        templates = [GraphTemplateCPUFreq]
 
-       cpuid_pattern = re.compile(r"cpu[0-9]+")
-
        @property
        def objects(self):
                core_ids = []
 
                for cpuid in os.listdir("/sys/devices/system/cpu"):
-                       if not self.cpuid_pattern.match(cpuid):
+                       if not re.match(r"cpu[0-9]+", cpuid):
                                continue
 
                        o = CPUFreqObject(self, cpuid)
index fe5e0b97b778bf3e935877da31308a4239200a88..8b66ceefaa736ec03ebc95bced8d9cd27bd1f1c4 100644 (file)
@@ -292,8 +292,8 @@ class DiskPlugin(base.Plugin):
        ]
 
        block_device_patterns = [
-               re.compile(r"(x?v|s)d[a-z]+"),
-               re.compile(r"mmcblk[0-9]+"),
+               r"(x?v|s)d[a-z]+",
+               r"mmcblk[0-9]+",
        ]
 
        @property
@@ -315,7 +315,7 @@ class DiskPlugin(base.Plugin):
        def _valid_block_device_name(self, name):
                # Check if the given name matches any of the valid patterns.
                for pattern in self.block_device_patterns:
-                       if pattern.match(name):
+                       if re.match(pattern, name):
                                return True
 
                return False
index e17d576219f65000607d9cb18e2ea32318eaaa0d..668ac37b99203b485a4df141df4c0c3546cc43ec 100644 (file)
@@ -66,7 +66,7 @@ class SystemInterruptsObject(base.Object):
                return "default"
 
        def collect(self):
-               expr = re.compile(r"^intr (\d+)")
+               expr = r"^intr (\d+)"
 
                with open("/proc/stat") as f:
                        for line in f.readlines():