commit 79f358d410f327ff7ca421c1d090e132dfb1f8c3
parent d26c688f0bcd03b7be2bfadc41cbb2693d9788d4
Author: serge-sans-paille <sguelton@mozilla.com>
Date: Mon, 8 Dec 2025 20:43:19 +0000
Bug 2002887 - Special manifestparser.util.normsep based on os property r=jcristau
It's funny to see how this kind of code hoisting is simple to write in
Python.
It saves ~170ms during task graph construction on a Linux machine.
Differential Revision: https://phabricator.services.mozilla.com/D274360
Diffstat:
1 file changed, 46 insertions(+), 17 deletions(-)
diff --git a/testing/mozbase/manifestparser/manifestparser/util.py b/testing/mozbase/manifestparser/manifestparser/util.py
@@ -5,25 +5,54 @@
import ast
import os
+# The normsep function is used everywhere, it's important enough in terms of
+# optimization to justify the slight duplication that can be found below.
+#
+# TODO: Have a dedicated function for bytes and one for unicode.
+if os.altsep and os.altsep != "/":
+ altsep_b = os.altsep.encode("ascii")
+if os.sep != "/":
+ sep_b = os.sep.encode("ascii")
-def normsep(path):
- """
- Normalize path separators, by using forward slashes instead of whatever
- :py:const:`os.sep` is.
- """
- if os.sep != "/":
- # Python 2 is happy to do things like byte_string.replace(u'foo',
- # u'bar'), but not Python 3.
- if isinstance(path, bytes):
- path = path.replace(os.sep.encode("ascii"), b"/")
- else:
- path = path.replace(os.sep, "/")
+if os.sep != "/":
+ if os.altsep and os.altsep != "/":
+
+ def normsep(path):
+ """
+ Normalize path separators, by using forward slashes instead of whatever
+ :py:const:`os.sep` is.
+ """
+ # Python 2 is happy to do things like byte_string.replace(u'foo',
+ # u'bar'), but not Python 3.
+ if isinstance(path, bytes):
+ path = path.replace(sep_b, b"/")
+ return path.replace(altsep_b, b"/")
+ else:
+ path = path.replace(os.sep, "/")
+ return path.replace(os.altsep, "/")
+
+ else:
+
+ def normsep(path):
+ if isinstance(path, bytes):
+ return path.replace(sep_b, b"/")
+ else:
+ return path.replace(os.sep, "/")
+
+else:
if os.altsep and os.altsep != "/":
- if isinstance(path, bytes):
- path = path.replace(os.altsep.encode("ascii"), b"/")
- else:
- path = path.replace(os.altsep, "/")
- return path
+
+ def normsep(path):
+ if isinstance(path, bytes):
+ return path.replace(altsep_b, b"/")
+ else:
+ return path.replace(os.altsep, "/")
+ return path
+
+ else:
+
+ def normsep(path):
+ return path
def evaluate_list_from_string(list_string):