For checking whether a substring is present in a string,
using the pattern:
"str" in string
is slightly faster than:
string.find("str") != -1
Use it to shave off 4 % of the runtime of this script that
processes quite a few long source files.
Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
scripts/check-aclrules.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/scripts/check-aclrules.py b/scripts/check-aclrules.py
index e06a019b00..d145e59164 100755
--- a/scripts/check-aclrules.py
+++ b/scripts/check-aclrules.py
@@ -97,7 +97,7 @@ def fixup_name(name):
def name_to_ProcName(name):
elems = []
- if name.find("_") != -1 or name.lower() in ["open", "close"]:
+ if "_" in name or name.lower() in ["open", "close"]:
elems = [n.lower().capitalize() for n in name.split("_")]
else:
elems = [name]
@@ -116,11 +116,11 @@ with open(proto, "r") as fh:
filtered = False
for line in fh:
- if line.find("/**") != -1:
+ if "/**" in line:
incomment = True
filtered = False
elif incomment:
- if line.find("* @aclfilter") != -1:
+ if "* @aclfilter" in line:
filtered = True
elif filtered:
m = re.search(r'''REMOTE_PROC_(.*)\s+=\s*\d+''', line)
@@ -211,7 +211,7 @@ def process_file(filename):
# an ACL function
if intable:
assign = re.search(r'''\.(\w+)\s*=\s*(\w+),?''', line)
- if line.find("}") != -1:
+ if "}" in line:
intable = False
table = None
elif assign is not None:
@@ -247,9 +247,9 @@ def process_file(filename):
intable = True
table = name
- if line.find("{") != -1:
+ if "{" in line:
brace = brace + 1
- if line.find("}") != -1:
+ if "}" in line:
brace = brace - 1
return errs
--
2.19.2
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Wed, Nov 20, 2019 at 07:32:45PM +0100, Ján Tomko wrote:
> For checking whether a substring is present in a string,
> using the pattern:
> "str" in string
> is slightly faster than:
> string.find("str") != -1
>
> Use it to shave off 4 % of the runtime of this script that
> processes quite a few long source files.
>
This is also the case in python FWIW...
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
Reviewed-by: Erik Skultety <eskultet@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Thu, Nov 21, 2019 at 09:27:31AM +0100, Erik Skultety wrote:
> On Wed, Nov 20, 2019 at 07:32:45PM +0100, Ján Tomko wrote:
> > For checking whether a substring is present in a string,
> > using the pattern:
> > "str" in string
> > is slightly faster than:
> > string.find("str") != -1
> >
> > Use it to shave off 4 % of the runtime of this script that
> > processes quite a few long source files.
> >
>
> This is also the case in python FWIW...
Derp...clearly I didn't have my cup of coffee in the morning, since I thought
this was related to perl, sorry for the noise.
Erik
>
> > Signed-off-by: Ján Tomko <jtomko@redhat.com>
> > ---
>
> Reviewed-by: Erik Skultety <eskultet@redhat.com>
>
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2026 Red Hat, Inc.