Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove get_id() hotspot #14108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
extract_as_list, typeslistify, stringlistify, classify_unity_sources,
get_filenames_templates_dict, substitute_values, has_path_sep,
PerMachineDefaultable,
MesonBugException, EnvironmentVariables, pickle_load,
MesonBugException, EnvironmentVariables, pickle_load, lazy_property,
)
from .options import OptionKey

Expand Down Expand Up @@ -637,13 +637,17 @@ def construct_id_from_path(subdir: str, name: str, type_suffix: str) -> str:
return subdir_part + '@@' + my_id
return my_id

def get_id(self) -> str:
@lazy_property
def id(self) -> str:
name = self.name
if getattr(self, 'name_suffix_set', False):
name += '.' + self.suffix
return self.construct_id_from_path(
self.subdir, name, self.type_suffix())

def get_id(self) -> str:
return self.id

def process_kwargs_base(self, kwargs: T.Dict[str, T.Any]) -> None:
if 'build_by_default' in kwargs:
self.build_by_default = kwargs['build_by_default']
Expand Down
11 changes: 9 additions & 2 deletions mesonbuild/utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2392,10 +2392,17 @@ class lazy_property(T.Generic[_T]):
Due to Python's MRO that means that the calculated value will be found
before this property, speeding up subsequent lookups.
"""
def __init__(self, func: T.Callable[[T.Any], _T]):
def __init__(self, func: T.Callable[[T.Any], _T]) -> None:
self.__name: T.Optional[str] = None
self.__func = func

def __set_name__(self, owner: T.Any, name: str) -> None:
if self.__name is None:
self.__name = name
else:
assert name == self.__name

def __get__(self, instance: object, cls: T.Type) -> _T:
value = self.__func(instance)
setattr(instance, self.__func.__name__, value)
setattr(instance, self.__name, value)
return value
Loading