Skip to content

Commit

Permalink
Remove indirection for OptionKey.as_root() et al.
Browse files Browse the repository at this point in the history
Removes one function call and a few comparisons.
  • Loading branch information
bruchar1 committed Feb 14, 2025
1 parent b117c7e commit eb1aaf9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions mesonbuild/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,19 @@ def evolve(self,
subproject if subproject != _BAD_VALUE else self.subproject, # None is a valid value so it can'the default value in method declaration.
machine if machine is not None else self.machine)

def as_root(self) -> 'OptionKey':
def as_root(self) -> OptionKey:
"""Convenience method for key.as_root()."""
if self.subproject is None or self.subproject == '':
if not self.subproject:
return self
return self.evolve(subproject='')
return OptionKey(self.name, subproject='', machine=self.machine)

def as_build(self) -> 'OptionKey':
def as_build(self) -> OptionKey:
"""Convenience method for key.as_build()."""
return self.evolve(machine=MachineChoice.BUILD)
return OptionKey(self.name, self.subproject, machine=MachineChoice.BUILD)

def as_host(self) -> 'OptionKey':
def as_host(self) -> OptionKey:
"""Convenience method for key.as_host()."""
return self.evolve(machine=MachineChoice.HOST)
return OptionKey(self.name, self.subproject, machine=MachineChoice.HOST)

def has_module_prefix(self) -> bool:
return '.' in self.name
Expand Down Expand Up @@ -833,7 +833,7 @@ def get_value_object_for(self, key: 'T.Union[OptionKey, str]') -> AnyOptionType:
return potential
else:
if potential is None:
parent_key = key.evolve(subproject=None)
parent_key = OptionKey(key.name, subproject=None, machine=key.machine)
if parent_key not in self.options:
raise KeyError(f'Tried to access nonexistant project parent option {parent_key}.')
return self.options[parent_key]
Expand Down

0 comments on commit eb1aaf9

Please sign in to comment.