Skip to content

Commit 7a86cc6

Browse files
[lldb][NFC] Remove unnecessary std::string temporaries
The existing code was taking three substrings from a regex match and converting to std::strings prior to using them. This may have been done to address null-termination concerns, but this is not the case: 1. `name` was being used to call `c_str()` and then implicitly converted back to a `StringRef` on the call to `ToAddress`. While the path `const char *` -> `StringRef` requires null-termination, we can simply use the original StringRef. 2. `str_offset` was being converted back to a StringRef in order to call a member method. Member methods can't handle non-null termination. 3. `sign` simply had it's 0-th element accessed.
1 parent 503dbe7 commit 7a86cc6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lldb/source/Interpreter/OptionArgParser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ OptionArgParser::DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s,
243243
llvm::SmallVector<llvm::StringRef, 4> matches;
244244
if (g_symbol_plus_offset_regex.Execute(sref, &matches)) {
245245
uint64_t offset = 0;
246-
std::string name = matches[1].str();
247-
std::string sign = matches[2].str();
248-
std::string str_offset = matches[3].str();
249-
if (!llvm::StringRef(str_offset).getAsInteger(0, offset)) {
246+
llvm::StringRef name = matches[1];
247+
llvm::StringRef sign = matches[2];
248+
llvm::StringRef str_offset = matches[3];
249+
if (!str_offset.getAsInteger(0, offset)) {
250250
Status error;
251-
addr = ToAddress(exe_ctx, name.c_str(), LLDB_INVALID_ADDRESS, &error);
251+
addr = ToAddress(exe_ctx, name, LLDB_INVALID_ADDRESS, &error);
252252
if (addr != LLDB_INVALID_ADDRESS) {
253253
if (sign[0] == '+')
254254
return addr + offset;

0 commit comments

Comments
 (0)