Skip to content

[memprof] Use std::unique_ptr instead of std::optional #94655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions llvm/include/llvm/ProfileData/MemProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct Frame {
GlobalValue::GUID Function;
// The symbol name for the function. Only populated in the Frame by the reader
// if requested during initialization. This field should not be serialized.
std::optional<std::string> SymbolName;
std::unique_ptr<std::string> SymbolName;
// The source line offset of the call from the beginning of parent function.
uint32_t LineOffset;
// The source column number of the call to help distinguish multiple calls
Expand All @@ -210,7 +210,9 @@ struct Frame {

Frame(const Frame &Other) {
Function = Other.Function;
SymbolName = Other.SymbolName;
SymbolName = Other.SymbolName
? std::make_unique<std::string>(*Other.SymbolName)
: nullptr;
LineOffset = Other.LineOffset;
Column = Other.Column;
IsInlineFrame = Other.IsInlineFrame;
Expand All @@ -228,7 +230,9 @@ struct Frame {

Frame &operator=(const Frame &Other) {
Function = Other.Function;
SymbolName = Other.SymbolName;
SymbolName = Other.SymbolName
? std::make_unique<std::string>(*Other.SymbolName)
: nullptr;
LineOffset = Other.LineOffset;
Column = Other.Column;
IsInlineFrame = Other.IsInlineFrame;
Expand All @@ -237,10 +241,10 @@ struct Frame {

bool operator!=(const Frame &Other) const { return !operator==(Other); }

bool hasSymbolName() const { return SymbolName.has_value(); }
bool hasSymbolName() const { return !!SymbolName; }

StringRef getSymbolName() const {
assert(SymbolName.has_value());
assert(hasSymbolName());
return *SymbolName;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/MemProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ Error RawMemProfReader::readNextRecord(
return F;
auto Iter = this->GuidToSymbolName.find(F.Function);
assert(Iter != this->GuidToSymbolName.end());
F.SymbolName = Iter->getSecond();
F.SymbolName = std::make_unique<std::string>(Iter->getSecond());
return F;
};
return MemProfReader::readNextRecord(GuidRecord, IdToFrameCallback);
Expand Down
Loading