From b2061f1cf9f5fda32e9423f8a5f0a82fc4c473c3 Mon Sep 17 00:00:00 2001 From: Allen Date: Wed, 20 Nov 2024 18:54:22 +0800 Subject: [PATCH] [ios] Using `UnsafeBufferPointer` to skip data copying and boost performance. (#2686) * [ios] Using UnsafeBufferPointer to skip data copying and boost performance. * [ios] Fix the extra data copying caused by using and move the guard let condition to be earlier --- .../spine-cpp-lite/spine-cpp-lite-codegen.py | 46 ++- .../Extensions/RenderCommand+Vertices.swift | 2 +- .../Spine/Spine.Generated+Extensions.swift | 12 +- spine-ios/Sources/Spine/Spine.Generated.swift | 312 +++++++++++------- 4 files changed, 227 insertions(+), 145 deletions(-) diff --git a/spine-cpp/spine-cpp-lite/spine-cpp-lite-codegen.py b/spine-cpp/spine-cpp-lite/spine-cpp-lite-codegen.py index 9a0c6e596..e0d0b420c 100644 --- a/spine-cpp/spine-cpp-lite/spine-cpp-lite-codegen.py +++ b/spine-cpp/spine-cpp-lite/spine-cpp-lite-codegen.py @@ -239,8 +239,6 @@ class SwiftFunctionBodyWriter: if swift_return_type_is_array: body += self.write_array_call(num_function_name, function_call) - body += inset + inset - body += "}" else: if not self.spine_function.return_type == "void": body += "return " @@ -305,24 +303,46 @@ class SwiftFunctionBodyWriter: function_call += " != 0" return function_call - - def write_array_call(self, num_function_name, function_call): - array_call = f"let num = Int({num_function_name}({self.spine_object.var_name}))" + + def write_array_spine_class(self, num_function_name, function_call): + array_call = f"let ptr = {function_call}" array_call += "\n" array_call += inset + inset - array_call += f"let ptr = {function_call}" + array_call += "guard let validPtr = ptr else { return [] }" array_call += "\n" array_call += inset + inset - array_call += "return (0.. [Float] { let num = numVertices * 2 let ptr = spine_render_command_get_positions(wrappee) - return (0.. [Float] { let num = numVertices * 2 let ptr = spine_render_command_get_uvs(wrappee) - return (0..[Int32] { let num = numVertices let ptr = spine_render_command_get_colors(wrappee) - return (0..