8000 Reduce the number of in-memory Utf8Marshaler instances · rlazev/libgit2sharp@d4307c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit d4307c3

Browse files
committed
Reduce the number of in-memory Utf8Marshaler instances
1 parent f0178a0 commit d4307c3

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

LibGit2Sharp/Core/Utf8Marshaler.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace LibGit2Sharp.Core
66
{
77
internal class Utf8Marshaler : ICustomMarshaler
88
{
9-
static Utf8Marshaler staticInstance;
10-
readonly bool ownsPointer;
9+
private static readonly Utf8Marshaler staticInstance = new Utf8Marshaler();
10+
private readonly bool ownsPointer;
1111

1212
internal Utf8Marshaler(bool ownsPointer = false)
1313
{
@@ -89,11 +89,6 @@ public int GetNativeDataSize()
8989

9090
public static ICustomMarshaler GetInstance(string cookie)
9191
{
92-
if (staticInstance == null)
93-
{
94-
return staticInstance = new Utf8Marshaler();
95-
}
96-
9792
return staticInstance;
9893
}
9994

LibGit2Sharp/Index.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Index : IEnumerable<IndexEntry>
1717
private readonly IndexSafeHandle handle;
1818
private readonly Repository repo;
1919

20-
private static readonly Utf8Marshaler utf8Marshaler = new Utf8Marshaler();
20+
private static readonly Utf8Marshaler utf8Marshaler = new Utf8Marshaler(true);
2121

2222
internal Index(Repository repo)
2323
{

LibGit2Sharp/IndexEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class IndexEntry : IEquatable<IndexEntry>
1414

1515
private Func<FileStatus> state;
1616

17-
private static readonly Utf8Marshaler marshaler = new Utf8Marshaler();
17+
private static readonly Utf8Marshaler marshaler = (Utf8Marshaler)Utf8Marshaler.GetInstance(string.Empty);
1818

1919
/// <summary>
2020
/// State of the version of the <see cref = "Blob" /> pointed at by this <see cref = "IndexEntry" />,

LibGit2Sharp/Signature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Signature
1313
private readonly string name;
1414
private readonly string email;
1515

16-
private static readonly Utf8Marshaler marshaler = new Utf8Marshaler();
16+
private static readonly Utf8Marshaler marshaler = (Utf8Marshaler)Utf8Marshaler.GetInstance(string.Empty);
1717

1818
internal Signature(IntPtr signaturePtr)
1919
{

0 commit comments

Comments
 (0)
0