Browse Source

Optimized/fixed marshaling for fields as there is no need to create a copied instance of the native object.

pull/49/merge
triton 12 years ago
parent
commit
cf8eaa3a35
  1. 3
      src/Generator/Generators/CLI/CLIMarshal.cs
  2. 1
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  3. 2
      src/Generator/Generators/Marshal.cs

3
src/Generator/Generators/CLI/CLIMarshal.cs

@ -185,8 +185,9 @@ namespace CppSharp.Generators.CLI
instance += "&"; instance += "&";
instance += Context.ReturnVarName; instance += Context.ReturnVarName;
var needsCopy = !(Context.Declaration is Field);
if (@class.IsRefType) if (@class.IsRefType && needsCopy)
{ {
var name = Generator.GeneratedIdentifier(Context.ReturnVarName); var name = Generator.GeneratedIdentifier(Context.ReturnVarName);
Context.SupportBefore.WriteLine("auto {0} = new ::{1}({2});", name, Context.SupportBefore.WriteLine("auto {0} = new ::{1}({2});", name,

1
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -336,6 +336,7 @@ namespace CppSharp.Generators.CLI
var ctx = new MarshalContext(Driver) var ctx = new MarshalContext(Driver)
{ {
Declaration = decl,
ArgName = decl.Name, ArgName = decl.Name,
ReturnVarName = variable, ReturnVarName = variable,
ReturnType = decl.QualifiedType ReturnType = decl.QualifiedType

2
src/Generator/Generators/Marshal.cs

@ -19,6 +19,8 @@ namespace CppSharp.Generators
public TextGenerator SupportBefore { get; private set; } public TextGenerator SupportBefore { get; private set; }
public TextGenerator Return { get; private set; } public TextGenerator Return { get; private set; }
public Declaration Declaration { get; set; }
public string ReturnVarName { get; set; } public string ReturnVarName { get; set; }
public QualifiedType ReturnType { get; set; } public QualifiedType ReturnType { get; set; }

Loading…
Cancel
Save