diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-08-04 13:03:33 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-08-04 13:03:33 +0700 |
commit | ed02bb41f6de51b4ab1531369193e423a2b5837c (patch) | |
tree | 4ad49eb22264aa6acd2b5f5600800d0e56fdb0ef /crypto/src/asn1/DerObjectIdentifier.cs | |
parent | Asn1.Cmp updates from bc-java (diff) | |
download | BouncyCastle.NET-ed25519-ed02bb41f6de51b4ab1531369193e423a2b5837c.tar.xz |
Replace some locks with singleton init
Diffstat (limited to 'crypto/src/asn1/DerObjectIdentifier.cs')
-rw-r--r-- | crypto/src/asn1/DerObjectIdentifier.cs | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/crypto/src/asn1/DerObjectIdentifier.cs b/crypto/src/asn1/DerObjectIdentifier.cs index 91e427d0b..12e8ea0a8 100644 --- a/crypto/src/asn1/DerObjectIdentifier.cs +++ b/crypto/src/asn1/DerObjectIdentifier.cs @@ -168,8 +168,11 @@ namespace Org.BouncyCastle.Asn1 return new PrimitiveDerEncoding(tagClass, tagNo, GetContents()); } - private void DoOutput(MemoryStream bOut) + private byte[] GetContents() => Objects.EnsureSingletonInitialized(ref contents, identifier, CreateContents); + + private static byte[] CreateContents(string identifier) { + MemoryStream bOut = new MemoryStream(); OidTokenizer tok = new OidTokenizer(identifier); string token = tok.NextToken(); @@ -197,21 +200,8 @@ namespace Org.BouncyCastle.Asn1 Asn1RelativeOid.WriteField(bOut, new BigInteger(token)); } } - } - - private byte[] GetContents() - { - lock (this) - { - if (contents == null) - { - MemoryStream bOut = new MemoryStream(); - DoOutput(bOut); - contents = bOut.ToArray(); - } - return contents; - } + return bOut.ToArray(); } internal static DerObjectIdentifier CreatePrimitive(byte[] contents, bool clone) |