Skip to content

Commit

Permalink
Cleanup and use concurrent dictionary (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock authored Aug 15, 2024
1 parent dc4da49 commit 2fec0ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 278 deletions.
21 changes: 0 additions & 21 deletions src/Speckle.Core/Kits/HostAppVersion.cs

This file was deleted.

13 changes: 0 additions & 13 deletions src/Speckle.Core/Kits/HostApplication.cs

This file was deleted.

220 changes: 0 additions & 220 deletions src/Speckle.Core/Kits/HostApplications.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using Microsoft.CSharp.RuntimeBinder;

namespace Speckle.Sdk.Serialisation.SerializationUtilities;
Expand All @@ -11,33 +12,28 @@ internal static class CallSiteCache
// And also
// https://github.com/mgravell/fast-member/blob/master/FastMember/CallSiteCache.cs
// by Marc Gravell, https://github.com/mgravell
private static readonly Dictionary<string, CallSite<Func<CallSite, object, object?, object>>> s_setters = new();
private static readonly ConcurrentDictionary<string, CallSite<Func<CallSite, object, object?, object>>> s_setters =
new();

public static void SetValue(string propertyName, object target, object? value)
{
lock (s_setters)
{
CallSite<Func<CallSite, object, object?, object>>? site;

lock (s_setters)
var site = s_setters.GetOrAdd(
propertyName,
name =>
{
if (!s_setters.TryGetValue(propertyName, out site))
{
var binder = Binder.SetMember(
CSharpBinderFlags.None,
propertyName,
typeof(CallSiteCache),
new List<CSharpArgumentInfo>
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
}
);
s_setters[propertyName] = site = CallSite<Func<CallSite, object, object?, object>>.Create(binder);
}
var binder = Binder.SetMember(
CSharpBinderFlags.None,
name,
typeof(CallSiteCache),
new List<CSharpArgumentInfo>
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
}
);
return CallSite<Func<CallSite, object, object?, object>>.Create(binder);
}

site.Target.Invoke(site, target, value);
}
);
site.Target.Invoke(site, target, value);
}
}

0 comments on commit 2fec0ea

Please sign in to comment.