summary refs log tree commit diff
path: root/crypto/src/asn1/x9/X9ECParametersHolder.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-08-04 13:03:33 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-08-04 13:03:33 +0700
commited02bb41f6de51b4ab1531369193e423a2b5837c (patch)
tree4ad49eb22264aa6acd2b5f5600800d0e56fdb0ef /crypto/src/asn1/x9/X9ECParametersHolder.cs
parentAsn1.Cmp updates from bc-java (diff)
downloadBouncyCastle.NET-ed25519-ed02bb41f6de51b4ab1531369193e423a2b5837c.tar.xz
Replace some locks with singleton init
Diffstat (limited to 'crypto/src/asn1/x9/X9ECParametersHolder.cs')
-rw-r--r--crypto/src/asn1/x9/X9ECParametersHolder.cs39
1 files changed, 5 insertions, 34 deletions
diff --git a/crypto/src/asn1/x9/X9ECParametersHolder.cs b/crypto/src/asn1/x9/X9ECParametersHolder.cs
index ea72cc6ac..535dad9f7 100644
--- a/crypto/src/asn1/x9/X9ECParametersHolder.cs
+++ b/crypto/src/asn1/x9/X9ECParametersHolder.cs
@@ -1,4 +1,5 @@
 using Org.BouncyCastle.Math.EC;
+using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.X9
 {
@@ -7,42 +8,12 @@ namespace Org.BouncyCastle.Asn1.X9
         private ECCurve m_curve;
         private X9ECParameters m_parameters;
 
-        public ECCurve Curve
-        {
-            get
-            {
-                lock (this)
-                {
-                    if (m_curve == null)
-                    {
-                        m_curve = CreateCurve();
-                    }
+        public ECCurve Curve => Objects.EnsureSingletonInitialized(ref m_curve, this, self => self.CreateCurve());
 
-                    return m_curve;
-                }
-            }
-        }
+        public X9ECParameters Parameters =>
+            Objects.EnsureSingletonInitialized(ref m_parameters, this, self => self.CreateParameters());
 
-        public X9ECParameters Parameters
-		{
-			get
-			{
-                lock (this)
-                {
-                    if (m_parameters == null)
-                    {
-                        m_parameters = CreateParameters();
-                    }
-
-                    return m_parameters;
-                }
-            }
-        }
-
-        protected virtual ECCurve CreateCurve()
-        {
-            return CreateParameters().Curve;
-        }
+        protected virtual ECCurve CreateCurve() => Parameters.Curve;
 
         protected abstract X9ECParameters CreateParameters();
 	}