@@ -234,9 +234,10 @@ static json::Value extractValue(const CommentInfo &I) {
234
234
235
235
case CommentKind::CK_InlineCommandComment: {
236
236
json::Value ArgsArr = Array ();
237
+ auto &ARef = *ArgsArr.getAsArray ();
238
+ ARef.reserve (I.Args .size ());
237
239
for (const auto &Arg : I.Args )
238
- ArgsArr.getAsArray ()->emplace_back (Arg);
239
-
240
+ ARef.emplace_back (Arg);
240
241
Child.insert ({" Command" , I.Name });
241
242
Child.insert ({" Args" , ArgsArr});
242
243
Child.insert ({" Children" , ChildArr});
@@ -273,13 +274,15 @@ static json::Value extractValue(const CommentInfo &I) {
273
274
274
275
case CommentKind::CK_HTMLStartTagComment: {
275
276
json::Value AttrKeysArray = json::Array ();
276
- for (const auto &Key : I.AttrKeys )
277
- AttrKeysArray.getAsArray ()->emplace_back (Key);
278
-
279
277
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);
283
286
Child.insert ({" Name" , I.Name });
284
287
Child.insert ({" SelfClosing" , I.SelfClosing });
285
288
Child.insert ({" AttrKeys" , AttrKeysArray});
@@ -325,6 +328,7 @@ static void extractDescriptionFromInfo(ArrayRef<CommentInfo> Descriptions,
325
328
return ;
326
329
json::Value DescArr = Array ();
327
330
json::Array &DescARef = *DescArr.getAsArray ();
331
+ DescARef.reserve (Descriptions.size ());
328
332
for (const CommentInfo &Child : Descriptions)
329
333
DescARef.emplace_back (extractValue (Child));
330
334
EnumValObj.insert ({" EnumValueComments" , DescArr});
@@ -340,6 +344,7 @@ static json::Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir,
340
344
341
345
json::Value ParamArr = Array ();
342
346
json::Array &ParamARef = *ParamArr.getAsArray ();
347
+ ParamARef.reserve (I.Params .size ());
343
348
for (const auto Val : enumerate(I.Params )) {
344
349
json::Value V = Object ();
345
350
auto &VRef = *V.getAsObject ();
@@ -367,6 +372,7 @@ static json::Value extractValue(const EnumInfo &I,
367
372
Obj.insert ({" ID" , toHex (toStringRef (I.USR ))});
368
373
json::Value EnumArr = Array ();
369
374
json::Array &EnumARef = *EnumArr.getAsArray ();
375
+ EnumARef.reserve (I.Members .size ());
370
376
for (const EnumValueInfo &M : I.Members ) {
371
377
json::Value EnumValue = Object ();
372
378
auto &EnumValObj = *EnumValue.getAsObject ();
@@ -392,6 +398,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
392
398
const ClangDocContext &CDCtx) {
393
399
json::Value NamespaceArr = Array ();
394
400
json::Array &NamespaceARef = *NamespaceArr.getAsArray ();
401
+ NamespaceARef.reserve (S.Namespaces .size ());
395
402
for (const Reference &Child : S.Namespaces )
396
403
NamespaceARef.emplace_back (extractValue (Child, ParentInfoDir));
397
404
@@ -400,6 +407,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
400
407
401
408
json::Value RecordArr = Array ();
402
409
json::Array &RecordARef = *RecordArr.getAsArray ();
410
+ RecordARef.reserve (S.Records .size ());
403
411
for (const Reference &Child : S.Records )
404
412
RecordARef.emplace_back (extractValue (Child, ParentInfoDir));
405
413
@@ -408,12 +416,15 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
408
416
409
417
json::Value FunctionArr = Array ();
410
418
json::Array &FunctionARef = *FunctionArr.getAsArray ();
419
+ FunctionARef.reserve (S.Functions .size ());
411
420
412
421
json::Value PublicFunctionArr = Array ();
413
422
json::Array &PublicFunctionARef = *PublicFunctionArr.getAsArray ();
423
+ PublicFunctionARef.reserve (S.Functions .size ());
414
424
415
425
json::Value ProtectedFunctionArr = Array ();
416
426
json::Array &ProtectedFunctionARef = *ProtectedFunctionArr.getAsArray ();
427
+ ProtectedFunctionARef.reserve (S.Functions .size ());
417
428
418
429
for (const FunctionInfo &Child : S.Functions ) {
419
430
json::Value F = extractValue (Child, ParentInfoDir, CDCtx);
@@ -437,6 +448,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
437
448
438
449
json::Value EnumArr = Array ();
439
450
auto &EnumARef = *EnumArr.getAsArray ();
451
+ EnumARef.reserve (S.Enums .size ());
440
452
for (const EnumInfo &Child : S.Enums )
441
453
EnumARef.emplace_back (extractValue (Child, CDCtx));
442
454
@@ -445,6 +457,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
445
457
446
458
json::Value TypedefArr = Array ();
447
459
auto &TypedefARef = *TypedefArr.getAsArray ();
460
+ TypedefARef.reserve (S.Typedefs .size ());
448
461
for (const TypedefInfo &Child : S.Typedefs )
449
462
TypedefARef.emplace_back (extractValue (Child));
450
463
@@ -481,10 +494,13 @@ static json::Value extractValue(const RecordInfo &I,
481
494
extractScopeChildren (I.Children , RecordValue, BasePath, CDCtx);
482
495
json::Value PublicMembers = Array ();
483
496
json::Array &PubMemberRef = *PublicMembers.getAsArray ();
497
+ PubMemberRef.reserve (I.Members .size ());
484
498
json::Value ProtectedMembers = Array ();
485
499
json::Array &ProtMemberRef = *ProtectedMembers.getAsArray ();
500
+ ProtMemberRef.reserve (I.Members .size ());
486
501
json::Value PrivateMembers = Array ();
487
502
json::Array &PrivMemberRef = *PrivateMembers.getAsArray ();
503
+ PrivMemberRef.reserve (I.Members .size ());
488
504
for (const MemberTypeInfo &Member : I.Members ) {
489
505
json::Value MemberValue = Object ();
490
506
auto &MVRef = *MemberValue.getAsObject ();
@@ -516,20 +532,25 @@ static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
516
532
auto InfoPath = I->getRelativeFilePath (" " );
517
533
SmallString<128 > RelativePath = computeRelativePath (" " , InfoPath);
518
534
sys::path::native (RelativePath, sys::path::Style::posix);
535
+
536
+ auto *SSA = StylesheetArr.getAsArray ();
537
+ SSA->reserve (CDCtx.UserStylesheets .size ());
519
538
for (const auto &FilePath : CDCtx.UserStylesheets ) {
520
539
SmallString<128 > StylesheetPath = RelativePath;
521
540
sys::path::append (StylesheetPath, sys::path::Style::posix,
522
541
sys::path::filename (FilePath));
523
- StylesheetArr. getAsArray () ->emplace_back (StylesheetPath);
542
+ SSA ->emplace_back (StylesheetPath);
524
543
}
525
544
V.getAsObject ()->insert ({" Stylesheets" , StylesheetArr});
526
545
527
546
json::Value ScriptArr = Array ();
547
+ auto *SCA = ScriptArr.getAsArray ();
548
+ SCA->reserve (CDCtx.JsScripts .size ());
528
549
for (auto Script : CDCtx.JsScripts ) {
529
550
SmallString<128 > JsPath = RelativePath;
530
551
sys::path::append (JsPath, sys::path::Style::posix,
531
552
sys::path::filename (Script));
532
- ScriptArr. getAsArray () ->emplace_back (JsPath);
553
+ SCA ->emplace_back (JsPath);
533
554
}
534
555
V.getAsObject ()->insert ({" Scripts" , ScriptArr});
535
556
return Error::success ();
0 commit comments