diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-12-18 08:40:45 +0100 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-12-18 08:49:01 -0800 |
| commit | cc9c037493119dc43e2910d26688957fe60b63a7 (patch) | |
| tree | 3e406b2589eba19338a7367b8405922105982cfd /mesonbuild | |
| parent | 99d1a79e4885e4a1bbdcf12a3c6b212018468c7c (diff) | |
| download | meson-cc9c037493119dc43e2910d26688957fe60b63a7.tar.gz | |
options: optimize shortcuts for evolve()
Since OptionKey is immutable, it is possible to return self
if we know that the returned value is the same as the one
being transformed.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild')
| -rw-r--r-- | mesonbuild/options.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/mesonbuild/options.py b/mesonbuild/options.py index 8e29f29f3..78f9f7fe5 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -289,15 +289,21 @@ class OptionKey: def as_root(self) -> OptionKey: """Convenience method for key.evolve(subproject='').""" - return self.evolve(subproject='') + if self.subproject != '': + return self.evolve(subproject='') + return self def as_build(self) -> OptionKey: """Convenience method for key.evolve(machine=MachineChoice.BUILD).""" - return self.evolve(machine=MachineChoice.BUILD) + if self.machine != MachineChoice.BUILD: + return self.evolve(machine=MachineChoice.BUILD) + return self def as_host(self) -> OptionKey: """Convenience method for key.evolve(machine=MachineChoice.HOST).""" - return self.evolve(machine=MachineChoice.HOST) + if self.machine != MachineChoice.HOST: + return self.evolve(machine=MachineChoice.HOST) + return self def has_module_prefix(self) -> bool: return '.' in self.name @@ -835,7 +841,7 @@ class OptionStore: # # I did not do this yet, because it would make this MR even # more massive than it already is. Later then. - if not self.is_cross and key.machine == MachineChoice.BUILD: + if not self.is_cross: key = key.as_host() return key |
