Browse Source

Reduce calls to ConcurrentDictionary to improve performance (#1464)

pull/1467/head
josetr 5 years ago committed by GitHub
parent
commit
b9cf8f160a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 5
      src/Generator/Generators/CSharp/CSharpSources.cs

6
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -351,9 +351,9 @@ namespace CppSharp.Generators.CSharp @@ -351,9 +351,9 @@ namespace CppSharp.Generators.CSharp
if (originalClass.IsRefType)
{
Context.Before.WriteLine(
"else if ({0}.NativeToManagedMap.ContainsKey({1}))", qualifiedClass, Context.ReturnVarName);
Context.Before.WriteLineIndent("{0} = ({1}) {2}.NativeToManagedMap[{3}];",
ret, qualifiedIdentifier, qualifiedClass, Context.ReturnVarName);
"else if ({0}.NativeToManagedMap.TryGetValue({1}, out var {2}))", qualifiedClass, Context.ReturnVarName, ret + "Object");
Context.Before.WriteLineIndent("{0} = ({1}) {2};",
ret, qualifiedIdentifier, ret + "Object");
var dtor = originalClass.Destructors.FirstOrDefault();
if (dtor != null && dtor.IsVirtual)
{

5
src/Generator/Generators/CSharp/CSharpSources.cs

@ -1909,13 +1909,12 @@ namespace CppSharp.Generators.CSharp @@ -1909,13 +1909,12 @@ namespace CppSharp.Generators.CSharp
string.Join(", ", @params));
WriteOpenBraceAndIndent();
WriteLine($"if (!NativeToManagedMap.ContainsKey({Helpers.InstanceField}))");
WriteLine($"if (!NativeToManagedMap.TryGetValue({Helpers.InstanceField}, out var {Helpers.TargetIdentifier}Object))");
WriteLineIndent("throw new global::System.Exception(\"No managed instance was found\");");
NewLine();
var printedClass = @class.Visit(TypePrinter);
WriteLine($@"var {Helpers.TargetIdentifier} = ({
printedClass}) NativeToManagedMap[{Helpers.InstanceField}];");
WriteLine($@"var {Helpers.TargetIdentifier} = ({printedClass}){Helpers.TargetIdentifier}Object;");
WriteLine("if ({0}.{1})", Helpers.TargetIdentifier, Helpers.OwnsNativeInstanceIdentifier);
WriteLineIndent("{0}.SetupVTables();", Helpers.TargetIdentifier);
GenerateVTableManagedCall(method);

Loading…
Cancel
Save