diff --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py --- a/libcxx/utils/libcxx/test/dsl.py +++ b/libcxx/utils/libcxx/test/dsl.py @@ -297,6 +297,9 @@ """ assert self.isSupported(config), \ "Trying to get the name of a feature that is not supported in the given configuration" + return self._getNameUnchecked(config) + + def _getNameUnchecked(self, config): name = self._name(config) if callable(self._name) else self._name if not isinstance(name, str): raise ValueError("Feature did not resolve to a name that's a string, got {}".format(name)) @@ -316,7 +319,9 @@ """ assert self.isSupported(config), \ "Trying to enable feature {} that is not supported in the given configuration".format(self._name) + self._enableInUnchecked(config) + def _enableInUnchecked(self, config): addTo = lambda subs, sub, flag: [(s, x + ' ' + flag) if s == sub else (s, x) for (s, x) in subs] if self._compileFlag: compileFlag = self._compileFlag(config) if callable(self._compileFlag) else self._compileFlag @@ -324,8 +329,19 @@ if self._linkFlag: linkFlag = self._linkFlag(config) if callable(self._linkFlag) else self._linkFlag config.substitutions = addTo(config.substitutions, '%{link_flags}', linkFlag) - config.available_features.add(self.getName(config)) + config.available_features.add(self._getNameUnchecked(config)) + + def tryEnableIn(self, config): + """ + Try to enable a feature in a TestingConfig (if it is supported). + This is equivalent to `if isSupported(config): enabledIn(config)`, but + is slightly faster since it can omit redundant checks. + """ + if self.isSupported(config): + self._enableInUnchecked(config) + return True + return False def _str_to_bool(s): """ diff --git a/libcxx/utils/libcxx/test/newconfig.py b/libcxx/utils/libcxx/test/newconfig.py --- a/libcxx/utils/libcxx/test/newconfig.py +++ b/libcxx/utils/libcxx/test/newconfig.py @@ -25,9 +25,10 @@ # Then, apply the automatically-detected features. printFeatures = [] for feature in features: - if feature.isSupported(config): - feature.enableIn(config) - printFeatures.append(feature.getName(config)) + if feature.tryEnableIn(config): + # We can avoid a potentially expensive assertion and use + # _getNameUnchecked since we know that the feature is enabled. + printFeatures.append(feature._getNameUnchecked(config)) printFeatures = ["'{}'".format(f) for f in sorted(printFeatures)] lit_config.note("Enabling implicitly detected Lit features {}".format(', '.join(printFeatures)))