Skip to content

Commit

Permalink
Add cache to coredata.get_external_link_args
Browse files Browse the repository at this point in the history
  • Loading branch information
bruchar1 committed Jan 29, 2025
1 parent 31e8f86 commit fb435c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from . import mlog, options
import pickle, os, uuid
import sys
from functools import lru_cache
from itertools import chain
from pathlib import PurePath
from collections import OrderedDict, abc
Expand Down Expand Up @@ -582,6 +583,7 @@ def get_external_args(self, for_machine: MachineChoice, lang: str) -> T.List[str
key = OptionKey(f'{lang}_args', machine=for_machine)
return T.cast('T.List[str]', self.optstore.get_value(key))

@lru_cache(maxsize=None)
def get_external_link_args(self, for_machine: MachineChoice, lang: str) -> T.List[str]:
# mypy cannot analyze type of OptionKey
key = OptionKey(f'{lang}_link_args', machine=for_machine)
Expand Down
3 changes: 3 additions & 0 deletions unittests/allplatformstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4456,12 +4456,15 @@ def test_env_flags_to_linker(self) -> None:

# Test a compiler that acts as a linker
with mock.patch.object(cc_type, 'INVOKES_LINKER', True):
env.coredata.get_external_link_args.cache_clear()
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True, '')
link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
self.assertEqual(sorted(link_args), sorted(['-DCFLAG', '-flto']))


# And one that doesn't
with mock.patch.object(cc_type, 'INVOKES_LINKER', False):
env.coredata.get_external_link_args.cache_clear()
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True, '')
link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
self.assertEqual(sorted(link_args), sorted(['-flto']))
Expand Down

0 comments on commit fb435c0

Please sign in to comment.