From 43746f99d8a5d44fd3ffff149f6941583a9a1cec Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 4 Oct 2022 19:45:17 +0700 Subject: Save heap allocations --- crypto/src/math/ec/ECAlgorithms.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crypto/src/math/ec/ECAlgorithms.cs b/crypto/src/math/ec/ECAlgorithms.cs index 64e68fccc..fcfab06f7 100644 --- a/crypto/src/math/ec/ECAlgorithms.cs +++ b/crypto/src/math/ec/ECAlgorithms.cs @@ -213,9 +213,15 @@ namespace Org.BouncyCastle.Math.EC { ECCurve cp = p.Curve; if (!c.Equals(cp)) - throw new ArgumentException("Point must be on the same curve", "p"); + throw new ArgumentException("Point must be on the same curve", nameof(p)); +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + Span encoding = stackalloc byte[p.GetEncodedLength(false)]; + p.EncodeTo(false, encoding); + return c.DecodePoint(encoding); +#else return c.DecodePoint(p.GetEncoded(false)); +#endif } internal static ECPoint ImplCheckResult(ECPoint p) -- cgit 1.4.1