@@ -362,38 +362,45 @@ ValidateExecutableVisitor::ValidateExecutableVisitor(const std::shared_ptr<schem
362
362
const auto & mutationType = _schema->mutationType ();
363
363
const auto & subscriptionType = _schema->subscriptionType ();
364
364
365
- if (queryType)
366
- {
367
- _operationTypes[strQuery] = getValidateType (queryType);
368
- }
365
+ _operationTypes.reserve (3 );
369
366
370
367
if (mutationType)
371
368
{
372
369
_operationTypes[strMutation] = getValidateType (mutationType);
373
370
}
374
371
372
+ if (queryType)
373
+ {
374
+ _operationTypes[strQuery] = getValidateType (queryType);
375
+ }
376
+
375
377
if (subscriptionType)
376
378
{
377
379
_operationTypes[strSubscription] = getValidateType (subscriptionType);
378
380
}
379
381
380
382
const auto & types = _schema->types ();
381
383
384
+ _types.reserve (types.size ());
385
+
382
386
for (const auto & entry : types)
383
387
{
384
388
const auto name = entry.first ;
385
389
const auto kind = entry.second ->kind ();
386
390
387
391
if (!isScalarType (kind))
388
392
{
393
+ auto matchingTypes = std::move (_matchingTypes[name]);
394
+
389
395
if (kind == introspection::TypeKind::OBJECT)
390
396
{
391
- _matchingTypes[name] .emplace (name);
397
+ matchingTypes .emplace (name);
392
398
}
393
399
else
394
400
{
395
401
const auto & possibleTypes = entry.second ->possibleTypes ();
396
- internal::sorted_set<std::string_view> matchingTypes;
402
+
403
+ matchingTypes.reserve (possibleTypes.size ());
397
404
398
405
for (const auto & possibleType : possibleTypes)
399
406
{
@@ -404,18 +411,20 @@ ValidateExecutableVisitor::ValidateExecutableVisitor(const std::shared_ptr<schem
404
411
matchingTypes.emplace (spType->name ());
405
412
}
406
413
}
414
+ }
407
415
408
- if (!matchingTypes.empty ())
409
- {
410
- _matchingTypes[name] = std::move (matchingTypes);
411
- }
416
+ if (!matchingTypes.empty ())
417
+ {
418
+ _matchingTypes[name] = std::move (matchingTypes);
412
419
}
413
420
}
414
421
else if (kind == introspection::TypeKind::ENUM)
415
422
{
416
423
const auto & enumValues = entry.second ->enumValues ();
417
424
internal::sorted_set<std::string_view> values;
418
425
426
+ values.reserve (enumValues.size ());
427
+
419
428
for (const auto & value : enumValues)
420
429
{
421
430
if (value)
@@ -439,6 +448,8 @@ ValidateExecutableVisitor::ValidateExecutableVisitor(const std::shared_ptr<schem
439
448
440
449
const auto & directives = _schema->directives ();
441
450
451
+ _directives.reserve (directives.size ());
452
+
442
453
for (const auto & directive : directives)
443
454
{
444
455
const auto name = directive->name ();
@@ -1052,6 +1063,9 @@ bool ValidateExecutableVisitor::validateInputValue(
1052
1063
// result.
1053
1064
return false ;
1054
1065
}
1066
+
1067
+ // The recursive call may invalidate the iterator, so reacquire it.
1068
+ itrFields = getInputTypeFields (name);
1055
1069
}
1056
1070
1057
1071
subFields.emplace (entry.first );
0 commit comments