genbindings/cabi: reduce temporaries when returning qt heap copies

This commit is contained in:
mappu 2024-09-17 18:28:44 +12:00
parent 97f0141e27
commit 303d0f0b97
1 changed files with 3 additions and 3 deletions

View File

@ -351,9 +351,9 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
} }
} else if p.QtClassType() && !p.Pointer { } else if p.QtClassType() && !p.Pointer {
shouldReturn = p.ParameterType + " " + namePrefix + "_ret = "
afterCall = indent + "// Copy-construct value returned type into heap-allocated copy\n" // Elide temporary and emit directly from the rvalue
afterCall += indent + "" + assignExpression + "static_cast<" + p.ParameterType + "*>(new " + p.ParameterType + "(" + namePrefix + "_ret));\n" return indent + assignExpression + "new " + p.ParameterType + "(" + rvalue + ");\n"
} else if p.Const { } else if p.Const {
shouldReturn += "(" + p.RenderTypeCabi() + ") " shouldReturn += "(" + p.RenderTypeCabi() + ") "