This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Use std::string instead of llvm::Twine
ClosedPublic

Authored by JDevlieghere on Nov 5 2021, 12:54 PM.

Details

Summary

From the documentation:

A Twine is not intended for use directly and should not be stored, its implementation relies on the ability to store pointers to temporary stack objects which may be deallocated at the end of a statement. Twines should only be used accepted as const references in arguments, when an API wishes to accept possibly-concatenated strings.

rdar://84799118

Diff Detail

Event Timeline

JDevlieghere requested review of this revision.Nov 5 2021, 12:54 PM
JDevlieghere created this revision.
dblaikie accepted this revision.Nov 5 2021, 1:01 PM
dblaikie added a subscriber: dblaikie.

Looks good to me.

Alternatively the string concatenation could be inlined, then the Twine usage would be correct - but would still need an explicit "str()", like this:

SendPacketAndWaitForResponse(("QEnableCompression:type:" + avail_name + ";").str(), response)

Which may or may not be marginally faster because the Twine could cheaply compute the total length of the required buffer/presize the string... maybe.

This revision is now accepted and ready to land.Nov 5 2021, 1:01 PM
mgorny accepted this revision.Nov 5 2021, 1:11 PM
mgorny added inline comments.
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
1113

I'd personally prefer avail_name.str() instead of explicit std::string() but that's just me.

JDevlieghere marked an inline comment as done.Nov 5 2021, 1:17 PM
JDevlieghere added a subscriber: david.

@david: Yes, I considered it, but I think this is slightly more readable.

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
1113

Works for me. That actually makes it fit on a single line.

Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2021, 1:19 PM