Skip to content

Commit

Permalink
[lldb][NFCI] Remove unneccessary allocation in ScriptInterpreterPytho…
Browse files Browse the repository at this point in the history
…nImpl::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.
  • Loading branch information
bulbazord authored Sep 19, 2023
1 parent 45e6e4d commit d5a62b7
Showing 1 changed file with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2438,24 +2438,11 @@ ConstString ScriptInterpreterPythonImpl::GetSyntheticTypeName(
}

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

ConstString ret_val;
bool got_string = false;
std::string buffer;

if (py_return.IsAllocated() && PythonString::Check(py_return.get())) {
PythonString py_string(PyRefType::Borrowed, py_return.get());
llvm::StringRef return_data(py_string.GetString());
if (!return_data.empty()) {
buffer.assign(return_data.data(), return_data.size());
got_string = true;
}
}

if (got_string)
ret_val.SetCStringWithLength(buffer.c_str(), buffer.size());

return ret_val;
PythonString type_name(PyRefType::Borrowed, py_return.get());
return ConstString(py_string.GetString());
}

bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword(
Expand Down

0 comments on commit d5a62b7

Please sign in to comment.