@@ -208,37 +208,110 @@ static json::Value extractValue(const TypedefInfo &I) {
208
208
}
209
209
210
210
static json::Value extractValue (const CommentInfo &I) {
211
- assert ((I.Kind == " BlockCommandComment" || I.Kind == " FullComment" ||
212
- I.Kind == " ParagraphComment" || I.Kind == " TextComment" ) &&
213
- " Unknown Comment type in CommentInfo." );
214
-
215
211
Object Obj = Object ();
216
- json::Value Child = Object ();
217
212
218
- // TextComment has no children, so return it.
219
- if (I.Kind == " TextComment" ) {
220
- Obj.insert ({" TextComment" , I.Text });
221
- return Obj;
222
- }
213
+ json::Value ChildVal = Object ();
214
+ Object &Child = *ChildVal.getAsObject ();
223
215
224
- // BlockCommandComment needs to generate a Command key.
225
- if (I.Kind == " BlockCommandComment" )
226
- Child.getAsObject ()->insert ({" Command" , I.Name });
227
-
228
- // Use the same handling for everything else.
229
- // Only valid for:
230
- // - BlockCommandComment
231
- // - FullComment
232
- // - ParagraphComment
233
216
json::Value ChildArr = Array ();
234
217
auto &CARef = *ChildArr.getAsArray ();
235
218
CARef.reserve (I.Children .size ());
236
219
for (const auto &C : I.Children )
237
220
CARef.emplace_back (extractValue (*C));
238
- Child.getAsObject ()->insert ({" Children" , ChildArr});
239
- Obj.insert ({I.Kind , Child});
240
221
241
- return Obj;
222
+ switch (I.Kind ) {
223
+ case CommentKind::CK_TextComment: {
224
+ Obj.insert ({commentKindToString (I.Kind ), I.Text });
225
+ return Obj;
226
+ }
227
+
228
+ case CommentKind::CK_BlockCommandComment: {
229
+ Child.insert ({" Command" , I.Name });
230
+ Child.insert ({" Children" , ChildArr});
231
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
232
+ return Obj;
233
+ }
234
+
235
+ case CommentKind::CK_InlineCommandComment: {
236
+ json::Value ArgsArr = Array ();
237
+ auto &ARef = *ArgsArr.getAsArray ();
238
+ ARef.reserve (I.Args .size ());
239
+ for (const auto &Arg : I.Args )
240
+ ARef.emplace_back (Arg);
241
+ Child.insert ({" Command" , I.Name });
242
+ Child.insert ({" Args" , ArgsArr});
243
+ Child.insert ({" Children" , ChildArr});
244
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
245
+ return Obj;
246
+ }
247
+
248
+ case CommentKind::CK_ParamCommandComment:
249
+ case CommentKind::CK_TParamCommandComment: {
250
+ Child.insert ({" ParamName" , I.ParamName });
251
+ Child.insert ({" Direction" , I.Direction });
252
+ Child.insert ({" Explicit" , I.Explicit });
253
+ Child.insert ({" Children" , ChildArr});
254
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
255
+ return Obj;
256
+ }
257
+
258
+ case CommentKind::CK_VerbatimBlockComment: {
259
+ Child.insert ({" Text" , I.Text });
260
+ if (!I.CloseName .empty ())
261
+ Child.insert ({" CloseName" , I.CloseName });
262
+ Child.insert ({" Children" , ChildArr});
263
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
264
+ return Obj;
265
+ }
266
+
267
+ case CommentKind::CK_VerbatimBlockLineComment:
268
+ case CommentKind::CK_VerbatimLineComment: {
269
+ Child.insert ({" Text" , I.Text });
270
+ Child.insert ({" Children" , ChildArr});
271
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
272
+ return Obj;
273
+ }
274
+
275
+ case CommentKind::CK_HTMLStartTagComment: {
276
+ json::Value AttrKeysArray = json::Array ();
277
+ json::Value AttrValuesArray = json::Array ();
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);
286
+ Child.insert ({" Name" , I.Name });
287
+ Child.insert ({" SelfClosing" , I.SelfClosing });
288
+ Child.insert ({" AttrKeys" , AttrKeysArray});
289
+ Child.insert ({" AttrValues" , AttrValuesArray});
290
+ Child.insert ({" Children" , ChildArr});
291
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
292
+ return Obj;
293
+ }
294
+
295
+ case CommentKind::CK_HTMLEndTagComment: {
296
+ Child.insert ({" Name" , I.Name });
297
+ Child.insert ({" Children" , ChildArr});
298
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
299
+ return Obj;
300
+ }
301
+
302
+ case CommentKind::CK_FullComment:
303
+ case CommentKind::CK_ParagraphComment: {
304
+ Child.insert ({" Children" , ChildArr});
305
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
306
+ return Obj;
307
+ }
308
+
309
+ case CommentKind::CK_Unknown: {
310
+ Obj.insert ({commentKindToString (I.Kind ), I.Text });
311
+ return Obj;
312
+ }
313
+ }
314
+ llvm_unreachable (" Unknown comment kind encountered." );
242
315
}
243
316
244
317
static void maybeInsertLocation (std::optional<Location> Loc,
@@ -255,6 +328,7 @@ static void extractDescriptionFromInfo(ArrayRef<CommentInfo> Descriptions,
255
328
return ;
256
329
json::Value DescArr = Array ();
257
330
json::Array &DescARef = *DescArr.getAsArray ();
331
+ DescARef.reserve (Descriptions.size ());
258
332
for (const CommentInfo &Child : Descriptions)
259
333
DescARef.emplace_back (extractValue (Child));
260
334
EnumValObj.insert ({" EnumValueComments" , DescArr});
@@ -270,6 +344,7 @@ static json::Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir,
270
344
271
345
json::Value ParamArr = Array ();
272
346
json::Array &ParamARef = *ParamArr.getAsArray ();
347
+ ParamARef.reserve (I.Params .size ());
273
348
for (const auto Val : enumerate(I.Params )) {
274
349
json::Value V = Object ();
275
350
auto &VRef = *V.getAsObject ();
@@ -297,6 +372,7 @@ static json::Value extractValue(const EnumInfo &I,
297
372
Obj.insert ({" ID" , toHex (toStringRef (I.USR ))});
298
373
json::Value EnumArr = Array ();
299
374
json::Array &EnumARef = *EnumArr.getAsArray ();
375
+ EnumARef.reserve (I.Members .size ());
300
376
for (const EnumValueInfo &M : I.Members ) {
301
377
json::Value EnumValue = Object ();
302
378
auto &EnumValObj = *EnumValue.getAsObject ();
@@ -322,6 +398,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
322
398
const ClangDocContext &CDCtx) {
323
399
json::Value NamespaceArr = Array ();
324
400
json::Array &NamespaceARef = *NamespaceArr.getAsArray ();
401
+ NamespaceARef.reserve (S.Namespaces .size ());
325
402
for (const Reference &Child : S.Namespaces )
326
403
NamespaceARef.emplace_back (extractValue (Child, ParentInfoDir));
327
404
@@ -330,6 +407,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
330
407
331
408
json::Value RecordArr = Array ();
332
409
json::Array &RecordARef = *RecordArr.getAsArray ();
410
+ RecordARef.reserve (S.Records .size ());
333
411
for (const Reference &Child : S.Records )
334
412
RecordARef.emplace_back (extractValue (Child, ParentInfoDir));
335
413
@@ -338,12 +416,15 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
338
416
339
417
json::Value FunctionArr = Array ();
340
418
json::Array &FunctionARef = *FunctionArr.getAsArray ();
419
+ FunctionARef.reserve (S.Functions .size ());
341
420
342
421
json::Value PublicFunctionArr = Array ();
343
422
json::Array &PublicFunctionARef = *PublicFunctionArr.getAsArray ();
423
+ PublicFunctionARef.reserve (S.Functions .size ());
344
424
345
425
json::Value ProtectedFunctionArr = Array ();
346
426
json::Array &ProtectedFunctionARef = *ProtectedFunctionArr.getAsArray ();
427
+ ProtectedFunctionARef.reserve (S.Functions .size ());
347
428
348
429
for (const FunctionInfo &Child : S.Functions ) {
349
430
json::Value F = extractValue (Child, ParentInfoDir, CDCtx);
@@ -367,6 +448,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
367
448
368
449
json::Value EnumArr = Array ();
369
450
auto &EnumARef = *EnumArr.getAsArray ();
451
+ EnumARef.reserve (S.Enums .size ());
370
452
for (const EnumInfo &Child : S.Enums )
371
453
EnumARef.emplace_back (extractValue (Child, CDCtx));
372
454
@@ -375,6 +457,7 @@ static void extractScopeChildren(const ScopeChildren &S, Object &Obj,
375
457
376
458
json::Value TypedefArr = Array ();
377
459
auto &TypedefARef = *TypedefArr.getAsArray ();
460
+ TypedefARef.reserve (S.Typedefs .size ());
378
461
for (const TypedefInfo &Child : S.Typedefs )
379
462
TypedefARef.emplace_back (extractValue (Child));
380
463
@@ -411,10 +494,13 @@ static json::Value extractValue(const RecordInfo &I,
411
494
extractScopeChildren (I.Children , RecordValue, BasePath, CDCtx);
412
495
json::Value PublicMembers = Array ();
413
496
json::Array &PubMemberRef = *PublicMembers.getAsArray ();
497
+ PubMemberRef.reserve (I.Members .size ());
414
498
json::Value ProtectedMembers = Array ();
415
499
json::Array &ProtMemberRef = *ProtectedMembers.getAsArray ();
500
+ ProtMemberRef.reserve (I.Members .size ());
416
501
json::Value PrivateMembers = Array ();
417
502
json::Array &PrivMemberRef = *PrivateMembers.getAsArray ();
503
+ PrivMemberRef.reserve (I.Members .size ());
418
504
for (const MemberTypeInfo &Member : I.Members ) {
419
505
json::Value MemberValue = Object ();
420
506
auto &MVRef = *MemberValue.getAsObject ();
@@ -446,20 +532,25 @@ static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
446
532
auto InfoPath = I->getRelativeFilePath (" " );
447
533
SmallString<128 > RelativePath = computeRelativePath (" " , InfoPath);
448
534
sys::path::native (RelativePath, sys::path::Style::posix);
535
+
536
+ auto *SSA = StylesheetArr.getAsArray ();
537
+ SSA->reserve (CDCtx.UserStylesheets .size ());
449
538
for (const auto &FilePath : CDCtx.UserStylesheets ) {
450
539
SmallString<128 > StylesheetPath = RelativePath;
451
540
sys::path::append (StylesheetPath, sys::path::Style::posix,
452
541
sys::path::filename (FilePath));
453
- StylesheetArr. getAsArray () ->emplace_back (StylesheetPath);
542
+ SSA ->emplace_back (StylesheetPath);
454
543
}
455
544
V.getAsObject ()->insert ({" Stylesheets" , StylesheetArr});
456
545
457
546
json::Value ScriptArr = Array ();
547
+ auto *SCA = ScriptArr.getAsArray ();
548
+ SCA->reserve (CDCtx.JsScripts .size ());
458
549
for (auto Script : CDCtx.JsScripts ) {
459
550
SmallString<128 > JsPath = RelativePath;
460
551
sys::path::append (JsPath, sys::path::Style::posix,
461
552
sys::path::filename (Script));
462
- ScriptArr. getAsArray () ->emplace_back (JsPath);
553
+ SCA ->emplace_back (JsPath);
463
554
}
464
555
V.getAsObject ()->insert ({" Scripts" , ScriptArr});
465
556
return Error::success ();
0 commit comments