VariantMatcher
variadicMatcherDescriptor(StringRef MatcherName, SourceRange NameRange,
ArrayRef<ParserValue> Args, Diagnostics *Error) {
- ArgT **InnerArgs = new ArgT *[Args.size()]();
+ SmallVector<ArgT *, 8> InnerArgsPtr;
+ InnerArgsPtr.resize_for_overwrite(Args.size());
+ SmallVector<ArgT, 8> InnerArgs;
+ InnerArgs.reserve(Args.size());
- bool HasError = false;
for (size_t i = 0, e = Args.size(); i != e; ++i) {
using ArgTraits = ArgTypeTraits<ArgT>;
if (!ArgTraits::hasCorrectType(Value)) {
Error->addError(Arg.Range, Error->ET_RegistryWrongArgType)
<< (i + 1) << ArgTraits::getKind().asString() << Value.getTypeAsString();
- HasError = true;
- break;
+ return {};
}
if (!ArgTraits::hasCorrectValue(Value)) {
if (llvm::Optional<std::string> BestGuess =
<< (i + 1) << ArgTraits::getKind().asString()
<< Value.getTypeAsString();
}
- HasError = true;
- break;
+ return {};
}
-
- InnerArgs[i] = new ArgT(ArgTraits::get(Value));
- }
-
- VariantMatcher Out;
- if (!HasError) {
- Out = outvalueToVariantMatcher(Func(llvm::makeArrayRef(InnerArgs,
- Args.size())));
+ InnerArgs.set_size(i + 1);
+ InnerArgsPtr[i] = new (&InnerArgs[i]) ArgT(ArgTraits::get(Value));
}
-
- for (size_t i = 0, e = Args.size(); i != e; ++i) {
- delete InnerArgs[i];
- }
- delete[] InnerArgs;
- return Out;
+ return outvalueToVariantMatcher(Func(InnerArgsPtr));
}
/// Matcher descriptor for variadic functions.