Skip to content

Commit d5a62b7

Browse files
authored
[lldb][NFCI] Remove unneccessary allocation in ScriptInterpreterPythonImpl::GetSyntheticTypeName (#66724)
Instead of copying memory out of the PythonString (via a std::string) and then using that to create a ConstString, it would make more sense to just create the ConstString from the original StringRef in the first place.
1 parent 45e6e4d commit d5a62b7

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

+4-17
Original file line numberDiff line numberDiff line change
@@ -2438,24 +2438,11 @@ ConstString ScriptInterpreterPythonImpl::GetSyntheticTypeName(
24382438
}
24392439

24402440
PythonObject py_return = std::move(expected_py_return.get());
2441+
if (!py_return.IsAllocated() || !PythonString::Check(py_return.get()))
2442+
return {};
24412443

2442-
ConstString ret_val;
2443-
bool got_string = false;
2444-
std::string buffer;
2445-
2446-
if (py_return.IsAllocated() && PythonString::Check(py_return.get())) {
2447-
PythonString py_string(PyRefType::Borrowed, py_return.get());
2448-
llvm::StringRef return_data(py_string.GetString());
2449-
if (!return_data.empty()) {
2450-
buffer.assign(return_data.data(), return_data.size());
2451-
got_string = true;
2452-
}
2453-
}
2454-
2455-
if (got_string)
2456-
ret_val.SetCStringWithLength(buffer.c_str(), buffer.size());
2457-
2458-
return ret_val;
2444+
PythonString type_name(PyRefType::Borrowed, py_return.get());
2445+
return ConstString(py_string.GetString());
24592446
}
24602447

24612448
bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword(

0 commit comments

Comments
 (0)