Skip to content

Commit 8094baa

Browse files
committed
using unsafe to optimize code
1 parent 2af78f2 commit 8094baa

File tree

6 files changed

+252
-188
lines changed

6 files changed

+252
-188
lines changed

GeographicLib/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PackageId>Sandwych.GeographicLib</PackageId>
55
<Title>This is an attempt to port the Java version of GeographicLib to C#.</Title>
66
<PackageTags>geographic;gis;geodesic;gnomonic;</PackageTags>
7-
<VersionPrefix>1.49.2</VersionPrefix>
7+
<VersionPrefix>1.49.3</VersionPrefix>
88
</PropertyGroup>
99

1010
<Import Project="../Shared.props" />

GeographicLib/GeoMath.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ public static double Polyval(int N, double[] p, int s, double x)
187187
return y;
188188
}
189189

190+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
191+
public static double Polyval(int N, in ReadOnlySpan<double> p, int s, double x)
192+
{
193+
double y = N < 0 ? 0 : p[s++];
194+
while (--N >= 0) y = y * x + p[s++];
195+
return y;
196+
}
197+
198+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
199+
public unsafe static double Polyval(int N, double* p, int s, double x)
200+
{
201+
double y = N < 0 ? 0 : p[s++];
202+
while (--N >= 0) y = y * x + p[s++];
203+
return y;
204+
}
205+
190206
[MethodImpl(MethodImplOptions.AggressiveInlining)]
191207
public static double AngRound(double x)
192208
{
@@ -267,6 +283,7 @@ public static Pair AngDiff(double x, double y)
267283
* The results obey exactly the elementary properties of the trigonometric
268284
* functions, e.g., sin 9&deg; = cos 81&deg; = &minus; sin 123456789&deg;.
269285
**********************************************************************/
286+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
270287
public static Pair Sincosd(double x)
271288
{
272289
// In order to minimize round-off errors, this function exactly reduces
@@ -303,6 +320,7 @@ public static Pair Sincosd(double x)
303320
* &minus;1) = &minus;180&deg;, for &epsilon; positive and tiny;
304321
* atan2d(&plusmn;0, 1) = &plusmn;0&deg;.
305322
**********************************************************************/
323+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
306324
public static double Atan2d(double y, double x)
307325
{
308326
// In order to minimize round-off errors, this function rearranges the

0 commit comments

Comments
 (0)