Skip to content

Commit ddbd817

Browse files
committed
[clang-doc] Reorder struct fields to have less padding
1 parent 69bec00 commit ddbd817

File tree

2 files changed

+67
-59
lines changed

2 files changed

+67
-59
lines changed

clang-tools-extra/clang-doc/Representation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ BaseRecordInfo::BaseRecordInfo() : RecordInfo() {}
400400
BaseRecordInfo::BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path,
401401
bool IsVirtual, AccessSpecifier Access,
402402
bool IsParent)
403-
: RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
403+
: RecordInfo(USR, Name, Path), Access(Access), IsVirtual(IsVirtual),
404404
IsParent(IsParent) {}
405405

406406
llvm::SmallString<16> Info::extractName() const {

clang-tools-extra/clang-doc/Representation.h

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,29 @@ struct CommentInfo {
8686
// the vector.
8787
bool operator<(const CommentInfo &Other) const;
8888

89-
CommentKind Kind = CommentKind::
90-
CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
91-
// TextComment, InlineCommandComment, HTMLStartTagComment,
92-
// HTMLEndTagComment, BlockCommandComment,
93-
// ParamCommandComment, TParamCommandComment,
94-
// VerbatimBlockComment, VerbatimBlockLineComment,
95-
// VerbatimLineComment).
96-
SmallString<64> Text; // Text of the comment.
97-
SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
89+
std::vector<std::unique_ptr<CommentInfo>>
90+
Children; // List of child comments for this CommentInfo.
9891
SmallString<8> Direction; // Parameter direction (for (T)ParamCommand).
92+
SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
9993
SmallString<16> ParamName; // Parameter name (for (T)ParamCommand).
10094
SmallString<16> CloseName; // Closing tag name (for VerbatimBlock).
101-
bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
102-
bool Explicit = false; // Indicates if the direction of a param is explicit
103-
// (for (T)ParamCommand).
95+
SmallString<64> Text; // Text of the comment.
10496
llvm::SmallVector<SmallString<16>, 4>
10597
AttrKeys; // List of attribute keys (for HTML).
10698
llvm::SmallVector<SmallString<16>, 4>
10799
AttrValues; // List of attribute values for each key (for HTML).
108100
llvm::SmallVector<SmallString<16>, 4>
109101
Args; // List of arguments to commands (for InlineCommand).
110-
std::vector<std::unique_ptr<CommentInfo>>
111-
Children; // List of child comments for this CommentInfo.
102+
CommentKind Kind = CommentKind::
103+
CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
104+
// TextComment, InlineCommandComment, HTMLStartTagComment,
105+
// HTMLEndTagComment, BlockCommandComment,
106+
// ParamCommandComment, TParamCommandComment,
107+
// VerbatimBlockComment, VerbatimBlockLineComment,
108+
// VerbatimLineComment).
109+
bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
110+
bool Explicit = false; // Indicates if the direction of a param is explicit
111+
// (for (T)ParamCommand).
112112
};
113113

114114
struct Reference {
@@ -119,13 +119,13 @@ struct Reference {
119119
// "GlobalNamespace" as the name, but an empty QualName).
120120
Reference(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
121121
InfoType IT = InfoType::IT_default)
122-
: USR(USR), Name(Name), QualName(Name), RefType(IT) {}
122+
: USR(USR), RefType(IT), Name(Name), QualName(Name) {}
123123
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
124124
StringRef Path = StringRef())
125-
: USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path) {}
125+
: USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path) {}
126126
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
127127
StringRef Path, SmallString<16> DocumentationFileName)
128-
: USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path),
128+
: USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path),
129129
DocumentationFileName(DocumentationFileName) {}
130130

131131
bool operator==(const Reference &Other) const {
@@ -145,6 +145,10 @@ struct Reference {
145145

146146
SymbolID USR = SymbolID(); // Unique identifier for referenced decl
147147

148+
InfoType RefType = InfoType::IT_default; // Indicates the type of this
149+
// Reference (namespace, record,
150+
// function, enum, default).
151+
148152
// Name of type (possibly unresolved). Not including namespaces or template
149153
// parameters (so for a std::vector<int> this would be "vector"). See also
150154
// QualName.
@@ -155,9 +159,6 @@ struct Reference {
155159
// Name.
156160
SmallString<16> QualName;
157161

158-
InfoType RefType = InfoType::IT_default; // Indicates the type of this
159-
// Reference (namespace, record,
160-
// function, enum, default).
161162
// Path of directory where the clang-doc generated file will be saved
162163
// (possibly unresolved)
163164
llvm::SmallString<128> Path;
@@ -277,21 +278,21 @@ struct MemberTypeInfo : public FieldTypeInfo {
277278
Other.Description);
278279
}
279280

281+
std::vector<CommentInfo> Description;
282+
280283
// Access level associated with this info (public, protected, private, none).
281284
// AS_public is set as default because the bitcode writer requires the enum
282285
// with value 0 to be used as the default.
283286
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
284287
AccessSpecifier Access = AccessSpecifier::AS_public;
285-
286-
std::vector<CommentInfo> Description; // Comment description of this field.
287288
bool IsStatic = false;
288289
};
289290

290291
struct Location {
291292
Location(int StartLineNumber = 0, int EndLineNumber = 0,
292293
StringRef Filename = StringRef(), bool IsFileInRootDir = false)
293-
: StartLineNumber(StartLineNumber), EndLineNumber(EndLineNumber),
294-
Filename(Filename), IsFileInRootDir(IsFileInRootDir) {}
294+
: Filename(Filename), StartLineNumber(StartLineNumber),
295+
EndLineNumber(EndLineNumber), IsFileInRootDir(IsFileInRootDir) {}
295296

296297
bool operator==(const Location &Other) const {
297298
return std::tie(StartLineNumber, EndLineNumber, Filename) ==
@@ -309,40 +310,24 @@ struct Location {
309310
std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
310311
}
311312

312-
int StartLineNumber = 0; // Line number of this Location.
313+
SmallString<32> Filename;
314+
int StartLineNumber = 0;
313315
int EndLineNumber = 0;
314-
SmallString<32> Filename; // File for this Location.
315-
bool IsFileInRootDir = false; // Indicates if file is inside root directory
316+
bool IsFileInRootDir = false;
316317
};
317318

318319
/// A base struct for Infos.
319320
struct Info {
320321
Info(InfoType IT = InfoType::IT_default, SymbolID USR = SymbolID(),
321322
StringRef Name = StringRef(), StringRef Path = StringRef())
322-
: USR(USR), IT(IT), Name(Name), Path(Path) {}
323+
: Path(Path), Name(Name), USR(USR), IT(IT) {}
323324

324325
Info(const Info &Other) = delete;
325326
Info(Info &&Other) = default;
326-
327327
virtual ~Info() = default;
328328

329329
Info &operator=(Info &&Other) = default;
330330

331-
SymbolID USR =
332-
SymbolID(); // Unique identifier for the decl described by this Info.
333-
InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
334-
SmallString<16> Name; // Unqualified name of the decl.
335-
llvm::SmallVector<Reference, 4>
336-
Namespace; // List of parent namespaces for this decl.
337-
std::vector<CommentInfo> Description; // Comment description of this decl.
338-
llvm::SmallString<128> Path; // Path of directory where the clang-doc
339-
// generated file will be saved
340-
341-
// The name used for the file that this info is documented in.
342-
// In the JSON generator, infos are documented in files with mangled names.
343-
// Thus, we keep track of the physical filename for linking purposes.
344-
SmallString<16> DocumentationFileName;
345-
346331
void mergeBase(Info &&I);
347332
bool mergeable(const Info &Other);
348333

@@ -353,6 +338,29 @@ struct Info {
353338

354339
/// Returns the basename that should be used for this Info.
355340
llvm::SmallString<16> getFileBaseName() const;
341+
342+
// Path of directory where the clang-doc generated file will be saved.
343+
llvm::SmallString<128> Path;
344+
345+
// Unqualified name of the decl.
346+
SmallString<16> Name;
347+
348+
// The name used for the file that this info is documented in.
349+
// In the JSON generator, infos are documented in files with mangled names.
350+
// Thus, we keep track of the physical filename for linking purposes.
351+
SmallString<16> DocumentationFileName;
352+
353+
// List of parent namespaces for this decl.
354+
llvm::SmallVector<Reference, 4> Namespace;
355+
356+
// Unique identifier for the decl described by this Info.
357+
SymbolID USR = SymbolID();
358+
359+
// InfoType of this particular Info.
360+
InfoType IT = InfoType::IT_default;
361+
362+
// Comment description of this decl.
363+
std::vector<CommentInfo> Description;
356364
};
357365

358366
// Info for namespaces.
@@ -426,21 +434,21 @@ struct FunctionInfo : public SymbolInfo {
426434

427435
void merge(FunctionInfo &&I);
428436

429-
bool IsMethod = false; // Indicates whether this function is a class method.
430-
Reference Parent; // Reference to the parent class decl for this method.
431-
TypeInfo ReturnType; // Info about the return type of this function.
432-
llvm::SmallVector<FieldTypeInfo, 4> Params; // List of parameters.
437+
Reference Parent;
438+
TypeInfo ReturnType;
439+
llvm::SmallVector<FieldTypeInfo, 4> Params;
440+
SmallString<256> Prototype;
441+
442+
// When present, this function is a template or specialization.
443+
std::optional<TemplateInfo> Template;
444+
433445
// Access level for this method (public, private, protected, none).
434446
// AS_public is set as default because the bitcode writer requires the enum
435447
// with value 0 to be used as the default.
436448
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
437449
AccessSpecifier Access = AccessSpecifier::AS_public;
438450

439-
// Function Prototype
440-
SmallString<256> Prototype;
441-
442-
// When present, this function is a template or specialization.
443-
std::optional<TemplateInfo> Template;
451+
bool IsMethod = false;
444452
};
445453

446454
// TODO: Expand to allow for documenting templating, inheritance access,
@@ -455,15 +463,15 @@ struct RecordInfo : public SymbolInfo {
455463
// Type of this record (struct, class, union, interface).
456464
TagTypeKind TagType = TagTypeKind::Struct;
457465

458-
// When present, this record is a template or specialization.
459-
std::optional<TemplateInfo> Template;
460-
461466
// Indicates if the record was declared using a typedef. Things like anonymous
462467
// structs in a typedef:
463468
// typedef struct { ... } foo_t;
464469
// are converted into records with the typedef as the Name + this flag set.
465470
bool IsTypeDef = false;
466471

472+
// When present, this record is a template or specialization.
473+
std::optional<TemplateInfo> Template;
474+
467475
llvm::SmallVector<MemberTypeInfo, 4>
468476
Members; // List of info about record members.
469477
llvm::SmallVector<Reference, 4> Parents; // List of base/parent records
@@ -508,11 +516,11 @@ struct BaseRecordInfo : public RecordInfo {
508516
BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, bool IsVirtual,
509517
AccessSpecifier Access, bool IsParent);
510518

511-
// Indicates if base corresponds to a virtual inheritance
512-
bool IsVirtual = false;
513519
// Access level associated with this inherited info (public, protected,
514520
// private).
515521
AccessSpecifier Access = AccessSpecifier::AS_public;
522+
// Indicates if base corresponds to a virtual inheritance
523+
bool IsVirtual = false;
516524
bool IsParent = false; // Indicates if this base is a direct parent
517525
};
518526

0 commit comments

Comments
 (0)