]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove unnecessary regex grouping
authorAngus Lees <gus@inodes.org>
Fri, 28 Nov 2014 01:18:49 +0000 (12:18 +1100)
committerAngus Lees <gus@inodes.org>
Tue, 23 Dec 2014 03:53:02 +0000 (14:53 +1100)
Several regexes in this class used had unnecessary (\s+) grouping.  This
change makes the regexes slightly cheaper by removing the need for the
regex engine to remember the whitespace that was matched.

Change-Id: I9381c213efe093dc472b0c7e9d7b303a0c7cb13b

neutron/plugins/sriovnicagent/pci_lib.py

index f4108086c1f4273998cfbe7c2500f326e89fedc4..3135012753675c458faf325081f182fb76d3116d 100644 (file)
@@ -28,10 +28,10 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
 
     wrapper for getting/setting pci device details using ip link...
     """
-    VF_PATTERN = "^vf(\s+)(?P<vf_index>\d+)(\s+)"
-    MAC_PATTERN = "MAC(\s+)(?P<mac>[a-fA-F0-9:]+),"
-    STATE_PATTERN = "(\s+)link-state(\s+)(?P<state>\w+)"
-    ANY_PATTERN = "(.*),"
+    VF_PATTERN = r"^vf\s+(?P<vf_index>\d+)\s+"
+    MAC_PATTERN = r"MAC\s+(?P<mac>[a-fA-F0-9:]+),"
+    STATE_PATTERN = r"\s+link-state\s+(?P<state>\w+)"
+    ANY_PATTERN = ".*,"
 
     VF_LINE_FORMAT = VF_PATTERN + MAC_PATTERN + ANY_PATTERN + STATE_PATTERN
     VF_DETAILS_REG_EX = re.compile(VF_LINE_FORMAT)