From efdfad65652f6adb350d753cd72f6cd271311b34 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 2 Dec 2021 00:31:33 +0100 Subject: [PATCH] Avoid redundant casts for function result in generated code No real changes, just avoid somewhat ridiculously looking consecutive casts to the same type in the generated code. --- Source/Modules/c.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx index adcc18384..9acaa9f69 100644 --- a/Source/Modules/c.cxx +++ b/Source/Modules/c.cxx @@ -2124,7 +2124,12 @@ public: const char* start = Char(tm); const char* p = strstr(start, "$result = "); if (p == start || (p && p[-1] == ' ')) { - Insert(tm, p - start + strlen("$result = "), NewStringf("(%s)", return_type.get())); + p += strlen("$result = "); + scoped_dohptr result_cast(NewStringf("(%s)", return_type.get())); + + // However don't add a cast which is already there. + if (strncmp(p, Char(result_cast), strlen(Char(result_cast))) != 0) + Insert(tm, p - start, result_cast); } Replaceall(tm, "$result", "result"); Replaceall(tm, "$owner", GetFlag(n, "feature:new") ? "1" : "0");