Skip to content

Commit 9258059

Browse files
Remove compiler conditions
1 parent b23aa22 commit 9258059

File tree

6 files changed

+3
-73
lines changed

6 files changed

+3
-73
lines changed

src/ImageSharp.Drawing/Shapes/Path.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,6 @@ private static ReadOnlySpan<char> TrimSeparator(ReadOnlySpan<char> data)
419419
return data.Slice(idx);
420420
}
421421

422-
#if !NETCOREAPP2_1_OR_GREATER
423-
private static unsafe float ParseFloat(ReadOnlySpan<char> str)
424-
{
425-
fixed (char* p = str)
426-
{
427-
return float.Parse(new string(p, 0, str.Length));
428-
}
429-
}
430-
#else
431422
private static float ParseFloat(ReadOnlySpan<char> str)
432423
=> float.Parse(str, provider: CultureInfo.InvariantCulture);
433-
#endif
434424
}

src/ImageSharp.Drawing/Shapes/PolygonClipper/Clipper.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ public IPath[] GenerateClippedShapes(ClippingOperation operation, IntersectionRu
4444

4545
for (int j = 0; j < path.Count; j++)
4646
{
47-
#if NET472
48-
Vector2 v = path[j];
49-
points[j] = new PointF((float)(v.X / (double)ScalingFactor), (float)(v.Y / (double)ScalingFactor));
50-
#else
5147
points[j] = path[j] / ScalingFactor;
52-
#endif
5348
}
5449

5550
shapes[index++] = new Polygon(points);
@@ -62,12 +57,7 @@ public IPath[] GenerateClippedShapes(ClippingOperation operation, IntersectionRu
6257

6358
for (int j = 0; j < path.Count; j++)
6459
{
65-
#if NET472
66-
Vector2 v = path[j];
67-
points[j] = new PointF((float)(v.X / (double)ScalingFactor), (float)(v.Y / (double)ScalingFactor));
68-
#else
6960
points[j] = path[j] / ScalingFactor;
70-
#endif
7161
}
7262

7363
shapes[index++] = new Polygon(points);

src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperOffset.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ public ComplexPolygon Execute(float width)
3939
var points = new PointF[pt.Count];
4040
for (int j = 0; j < pt.Count; j++)
4141
{
42-
#if NET472
43-
Vector2 v = pt[j];
44-
points[j] = new PointF((float)(v.X / (double)ScalingFactor), (float)(v.Y / (double)ScalingFactor));
45-
#else
4642
points[j] = pt[j] / ScalingFactor;
47-
#endif
4843
}
4944

5045
polygons[i] = new Polygon(points);

src/ImageSharp.Drawing/Shapes/PolygonClipper/PolygonOffsetter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void Execute(float delta, PathsF solution)
7777
this.ExecuteInternal(delta);
7878
if (this.groupList.Count == 0)
7979
{
80-
goto Error;
80+
return;
8181
}
8282

8383
// Clean up self-intersections.
@@ -99,8 +99,6 @@ public void Execute(float delta, PathsF solution)
9999
clipper.Execute(ClippingOperation.Union, FillRule.Positive, solution);
100100
}
101101

102-
Error:
103-
104102
// PolygonClipper will throw for unhandled exceptions but we need to explicitly capture an empty result.
105103
if (solution.Count == 0)
106104
{

src/ImageSharp.Drawing/Utilities/NumericUtilities.cs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,50 +38,6 @@ public static void AddToAllElements(this Span<float> span, float value)
3838
}
3939
}
4040

41-
// https://apisof.net/catalog/System.Numerics.BitOperations.Log2(UInt32)
42-
// BitOperations.Log2() has been introduced in .NET Core 3.0,
43-
// since we do target only 3.1+, we can detect it's presence by using SUPPORTS_RUNTIME_INTRINSICS
44-
// TODO: Ideally this should have a separate definition in Build.props, but that adaption should be done cross-repo. Using a workaround until then.
45-
#if SUPPORTS_RUNTIME_INTRINSICS
46-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
47-
public static int Log2(uint value) => BitOperations.Log2(value);
48-
49-
#else
50-
51-
#pragma warning disable SA1515, SA1414, SA1114, SA1201
52-
private static ReadOnlySpan<byte> Log2DeBruijn => new byte[32]
53-
{
54-
00, 09, 01, 10, 13, 21, 02, 29,
55-
11, 14, 16, 18, 22, 25, 03, 30,
56-
08, 12, 20, 28, 15, 17, 24, 07,
57-
19, 27, 23, 06, 26, 05, 04, 31
58-
};
59-
60-
// Adapted from:
61-
// https://github.com/dotnet/runtime/blob/5c65d891f203618245184fa54397ced0a8ca806c/src/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs#L205-L223
62-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
63-
public static int Log2(uint value)
64-
{
65-
// No AggressiveInlining due to large method size
66-
// Has conventional contract 0->0 (Log(0) is undefined)
67-
68-
// Fill trailing zeros with ones, eg 00010010 becomes 00011111
69-
value |= value >> 01;
70-
value |= value >> 02;
71-
value |= value >> 04;
72-
value |= value >> 08;
73-
value |= value >> 16;
74-
75-
// uint.MaxValue >> 27 is always in range [0 - 31] so we use Unsafe.AddByteOffset to avoid bounds check
76-
return Unsafe.AddByteOffset(
77-
// Using deBruijn sequence, k=2, n=5 (2^5=32) : 0b_0000_0111_1100_0100_1010_1100_1101_1101u
78-
ref MemoryMarshal.GetReference(Log2DeBruijn),
79-
// uint|long -> IntPtr cast on 32-bit platforms does expensive overflow checks not needed here
80-
(IntPtr)(int)((value * 0x07C4ACDDu) >> 27));
81-
}
82-
83-
#pragma warning restore
84-
#endif
8541
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8642
public static float ClampFloat(float value, float min, float max)
8743
{

src/ImageSharp.Drawing/Utilities/SortUtility.KeyValueSort.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using System.Numerics;
45
using System.Runtime.CompilerServices;
56

67
namespace SixLabors.ImageSharp.Drawing.Utilities;
@@ -44,7 +45,7 @@ private static void IntrospectiveSort(Span<float> keys, Span<TValue> values)
4445
{
4546
if (keys.Length > 1)
4647
{
47-
IntroSort(keys, values, 2 * (NumericUtilities.Log2((uint)keys.Length) + 1));
48+
IntroSort(keys, values, 2 * (BitOperations.Log2((uint)keys.Length) + 1));
4849
}
4950
}
5051

0 commit comments

Comments
 (0)