@@ -234,9 +234,10 @@ static json::Value extractValue(const CommentInfo &I) {
234234
235235 case CommentKind::CK_InlineCommandComment: {
236236 json::Value ArgsArr = Array ();
237+ auto &ARef = *ArgsArr.getAsArray ();
238+ ARef.reserve (I.Args .size ());
237239 for (const auto &Arg : I.Args )
238- ArgsArr.getAsArray ()->emplace_back (Arg);
239-
240+ ARef.emplace_back (Arg);
240241 Child.insert ({" Command" , I.Name });
241242 Child.insert ({" Args" , ArgsArr});
242243 Child.insert ({" Children" , ChildArr});
@@ -273,13 +274,15 @@ static json::Value extractValue(const CommentInfo &I) {
273274
274275 case CommentKind::CK_HTMLStartTagComment: {
275276 json::Value AttrKeysArray = json::Array ();
276- for (const auto &Key : I.AttrKeys )
277- AttrKeysArray.getAsArray ()->emplace_back (Key);
278-
279277 json::Value AttrValuesArray = json::Array ();
280- for (const auto &Val : I.AttrValues )
281- AttrValuesArray.getAsArray ()->emplace_back (Val);
282-
278+ auto &KeyArr = *AttrKeysArray.getAsArray ();
279+ auto &ValArr = *AttrValuesArray.getAsArray ();
280+ KeyArr.reserve (I.AttrKeys .size ());
281+ ValArr.reserve (I.AttrValues .size ());
282+ for (const auto &K : I.AttrKeys )
283+ KeyArr.emplace_back (K);
284+ for (const auto &V : I.AttrValues )
285+ ValArr.emplace_back (V);
283286 Child.insert ({" Name" , I.Name });
284287 Child.insert ({" SelfClosing" , I.SelfClosing });
285288 Child.insert ({" AttrKeys" , AttrKeysArray});
@@ -325,6 +328,7 @@ static void extractDescriptionFromInfo(ArrayRef<CommentInfo> Descriptions,
325328 return ;
326329 json::Value DescArr = Array ();
327330 json::Array &DescARef = *DescArr.getAsArray ();
331+ DescARef.reserve (Descriptions.size ());
328332 for (const CommentInfo &Child : Descriptions)
329333 DescARef.emplace_back (extractValue (Child));
330334 EnumValObj.insert ({" EnumValueComments" , DescArr});
@@ -340,6 +344,7 @@ static json::Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir,
340344
341345 json::Value ParamArr = Array ();
342346 json::Array &ParamARef = *ParamArr.getAsArray ();
347+ ParamARef.reserve (I.Params .size ());
343348 for (const auto Val : enumerate(I.Params )) {
344349 json::Value V = Object ();
345350 auto &VRef = *V.getAsObject ();
@@ -367,6 +372,7 @@ static json::Value extractValue(const EnumInfo &I,
367372 Obj.insert ({" ID" , toHex (toStringRef (I.USR ))});
368373 json::Value EnumArr = Array ();
369374 json::Array &EnumARef = *EnumArr.getAsArray ();
375+ EnumARef.reserve (I.Members .size ());
370376 for (const EnumValueInfo &M : I.Members ) {
371377 json::Value EnumValue = Object ();
372378 auto &EnumValObj = *EnumValue.getAsObject ();
@@ -392,6 +398,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
392398 const ClangDocContext &CDCtx) {
393399 json::Value NamespaceArr = Array ();
394400 json::Array &NamespaceARef = *NamespaceArr.getAsArray ();
401+ NamespaceARef.reserve (S.Namespaces .size ());
395402 for (const Reference &Child : S.Namespaces )
396403 NamespaceARef.emplace_back (extractValue (Child, ParentInfoDir));
397404
@@ -400,6 +407,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
400407
401408 json::Value RecordArr = Array ();
402409 json::Array &RecordARef = *RecordArr.getAsArray ();
410+ RecordARef.reserve (S.Records .size ());
403411 for (const Reference &Child : S.Records )
404412 RecordARef.emplace_back (extractValue (Child, ParentInfoDir));
405413
@@ -408,12 +416,15 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
408416
409417 json::Value FunctionArr = Array ();
410418 json::Array &FunctionARef = *FunctionArr.getAsArray ();
419+ FunctionARef.reserve (S.Functions .size ());
411420
412421 json::Value PublicFunctionArr = Array ();
413422 json::Array &PublicFunctionARef = *PublicFunctionArr.getAsArray ();
423+ PublicFunctionARef.reserve (S.Functions .size ());
414424
415425 json::Value ProtectedFunctionArr = Array ();
416426 json::Array &ProtectedFunctionARef = *ProtectedFunctionArr.getAsArray ();
427+ ProtectedFunctionARef.reserve (S.Functions .size ());
417428
418429 for (const FunctionInfo &Child : S.Functions ) {
419430 json::Value F = extractValue (Child, ParentInfoDir, CDCtx);
@@ -437,6 +448,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
437448
438449 json::Value EnumArr = Array ();
439450 auto &EnumARef = *EnumArr.getAsArray ();
451+ EnumARef.reserve (S.Enums .size ());
440452 for (const EnumInfo &Child : S.Enums )
441453 EnumARef.emplace_back (extractValue (Child, CDCtx));
442454
@@ -445,6 +457,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
445457
446458 json::Value TypedefArr = Array ();
447459 auto &TypedefARef = *TypedefArr.getAsArray ();
460+ TypedefARef.reserve (S.Typedefs .size ());
448461 for (const TypedefInfo &Child : S.Typedefs )
449462 TypedefARef.emplace_back (extractValue (Child));
450463
@@ -481,10 +494,13 @@ static json::Value extractValue(const RecordInfo &I,
481494 extractScopeChildren (I.Children , RecordValue, BasePath, CDCtx);
482495 json::Value PublicMembers = Array ();
483496 json::Array &PubMemberRef = *PublicMembers.getAsArray ();
497+ PubMemberRef.reserve (I.Members .size ());
484498 json::Value ProtectedMembers = Array ();
485499 json::Array &ProtMemberRef = *ProtectedMembers.getAsArray ();
500+ ProtMemberRef.reserve (I.Members .size ());
486501 json::Value PrivateMembers = Array ();
487502 json::Array &PrivMemberRef = *PrivateMembers.getAsArray ();
503+ PrivMemberRef.reserve (I.Members .size ());
488504 for (const MemberTypeInfo &Member : I.Members ) {
489505 json::Value MemberValue = Object ();
490506 auto &MVRef = *MemberValue.getAsObject ();
@@ -516,20 +532,25 @@ static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
516532 auto InfoPath = I->getRelativeFilePath (" " );
517533 SmallString<128 > RelativePath = computeRelativePath (" " , InfoPath);
518534 sys::path::native (RelativePath, sys::path::Style::posix);
535+
536+ auto *SSA = StylesheetArr.getAsArray ();
537+ SSA->reserve (CDCtx.UserStylesheets .size ());
519538 for (const auto &FilePath : CDCtx.UserStylesheets ) {
520539 SmallString<128 > StylesheetPath = RelativePath;
521540 sys::path::append (StylesheetPath, sys::path::Style::posix,
522541 sys::path::filename (FilePath));
523- StylesheetArr. getAsArray () ->emplace_back (StylesheetPath);
542+ SSA ->emplace_back (StylesheetPath);
524543 }
525544 V.getAsObject ()->insert ({" Stylesheets" , StylesheetArr});
526545
527546 json::Value ScriptArr = Array ();
547+ auto *SCA = ScriptArr.getAsArray ();
548+ SCA->reserve (CDCtx.JsScripts .size ());
528549 for (auto Script : CDCtx.JsScripts ) {
529550 SmallString<128 > JsPath = RelativePath;
530551 sys::path::append (JsPath, sys::path::Style::posix,
531552 sys::path::filename (Script));
532- ScriptArr. getAsArray () ->emplace_back (JsPath);
553+ SCA ->emplace_back (JsPath);
533554 }
534555 V.getAsObject ()->insert ({" Scripts" , ScriptArr});
535556 return Error::success ();
0 commit comments