From cf8eaa3a352f7512e1b503fbf4ddbc2a5e8f9b01 Mon Sep 17 00:00:00 2001 From: triton Date: Sun, 25 Aug 2013 23:24:09 +0100 Subject: [PATCH] Optimized/fixed marshaling for fields as there is no need to create a copied instance of the native object. --- src/Generator/Generators/CLI/CLIMarshal.cs | 3 ++- src/Generator/Generators/CLI/CLISourcesTemplate.cs | 1 + src/Generator/Generators/Marshal.cs | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs index 1ad00043..551b4095 100644 --- a/src/Generator/Generators/CLI/CLIMarshal.cs +++ b/src/Generator/Generators/CLI/CLIMarshal.cs @@ -185,8 +185,9 @@ namespace CppSharp.Generators.CLI instance += "&"; instance += Context.ReturnVarName; + var needsCopy = !(Context.Declaration is Field); - if (@class.IsRefType) + if (@class.IsRefType && needsCopy) { var name = Generator.GeneratedIdentifier(Context.ReturnVarName); Context.SupportBefore.WriteLine("auto {0} = new ::{1}({2});", name, diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index b13e854c..6625d2a6 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -336,6 +336,7 @@ namespace CppSharp.Generators.CLI var ctx = new MarshalContext(Driver) { + Declaration = decl, ArgName = decl.Name, ReturnVarName = variable, ReturnType = decl.QualifiedType diff --git a/src/Generator/Generators/Marshal.cs b/src/Generator/Generators/Marshal.cs index 783179f5..8129b2be 100644 --- a/src/Generator/Generators/Marshal.cs +++ b/src/Generator/Generators/Marshal.cs @@ -19,6 +19,8 @@ namespace CppSharp.Generators public TextGenerator SupportBefore { get; private set; } public TextGenerator Return { get; private set; } + public Declaration Declaration { get; set; } + public string ReturnVarName { get; set; } public QualifiedType ReturnType { get; set; }