Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/SIL.LCModel/Infrastructure/Impl/CmObjectSurrogate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace SIL.LCModel.Infrastructure.Impl
internal sealed class CmObjectSurrogate : ICmObjectSurrogate //, IEquatable<CmObjectSurrogate>
{
private static Dictionary<string, ConstructorInfo> s_classToConstructorInfo;
private static readonly object s_constructorLock = new object();
/// <summary>
/// It's common that hundreds of thousands of surrogates only use a few hundred class names. This is a local interning
/// of those names.
Expand Down Expand Up @@ -225,16 +226,19 @@ internal static CmObjectSurrogate CreateSnapshot(ICmObject obj)

internal static void InitializeConstructors(List<Type> cmObjectTypes)
{
if (s_classToConstructorInfo != null) return;

s_classToConstructorInfo = new Dictionary<string, ConstructorInfo>();
// Get default constructor.
// Only do this once, since they are stored in a static data member.
foreach (var lcmType in cmObjectTypes)
lock (s_constructorLock)
{
if (lcmType.IsAbstract) continue;
if (s_classToConstructorInfo != null) return;

s_classToConstructorInfo = new Dictionary<string, ConstructorInfo>();
// Get default constructor.
// Only do this once, since they are stored in a static data member.
foreach (var lcmType in cmObjectTypes)
{
if (lcmType.IsAbstract) continue;

s_classToConstructorInfo.Add(lcmType.Name, lcmType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null));
s_classToConstructorInfo.Add(lcmType.Name, lcmType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null));
}
}
}

Expand Down
Loading