diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-10-10 16:37:01 +0100 |
---|---|---|
committer | Benjamin Schubert <contact@benschubert.me> | 2019-10-10 17:31:34 +0100 |
commit | 2f3a5033bfd124a2bf46ed6bc160e219742159c6 (patch) | |
tree | 0a6ea469f573afee000925119df16bc984f8bacf | |
parent | e4c86c563aeab2f2a0a8cb8d29d1a4645c045254 (diff) | |
download | buildstream-2f3a5033bfd124a2bf46ed6bc160e219742159c6.tar.gz |
_platform/platform.py: Cache result from 'get_host_os'
'get_host_os' is an expensive method and is called twice per element.
Caching gives us some performance benefits.
-rw-r--r-- | src/buildstream/_platform/platform.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/buildstream/_platform/platform.py b/src/buildstream/_platform/platform.py index ca5fb7518..02e8924f8 100644 --- a/src/buildstream/_platform/platform.py +++ b/src/buildstream/_platform/platform.py @@ -32,6 +32,7 @@ from .. import utils class Platform(): _host_arch = None # cache to not recompute the host arch every time + _host_os = None # cache not to recompute the host os every time # Platform() # @@ -122,9 +123,11 @@ class Platform(): else: return min(cpu_count, cap) - @staticmethod - def get_host_os(): - return platform.uname().system + @classmethod + def get_host_os(cls): + if cls._host_os is None: + cls._host_os = platform.uname().system + return cls._host_os # canonicalize_arch(): # |