Skip to content

Commit ce1483b

Browse files
committed
Code refactoring to remove duplicate API
1 parent d7a33d4 commit ce1483b

File tree

1 file changed

+3
-29
lines changed

1 file changed

+3
-29
lines changed

Microsoft.Toolkit.HighPerformance/Buffers/StringPool.cs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
using System;
66
using System.Diagnostics.CodeAnalysis;
77
using System.Diagnostics.Contracts;
8-
#if NETCOREAPP3_1
9-
using System.Numerics;
10-
#endif
118
using System.Runtime.CompilerServices;
129
using System.Text;
1310
using Microsoft.Toolkit.HighPerformance.Extensions;
1411
#if !NETSTANDARD1_4
1512
using Microsoft.Toolkit.HighPerformance.Helpers;
1613
#endif
14+
using BitOperations = Microsoft.Toolkit.HighPerformance.Helpers.Internals.BitOperations;
1715

1816
#nullable enable
1917

@@ -79,8 +77,8 @@ static void FindFactors(int size, int factor, out int x, out int y)
7977
a = Math.Sqrt((double)size / factor),
8078
b = factor * a;
8179

82-
x = RoundUpPowerOfTwo((int)a);
83-
y = RoundUpPowerOfTwo((int)b);
80+
x = BitOperations.RoundUpPowerOfTwo((int)a);
81+
y = BitOperations.RoundUpPowerOfTwo((int)b);
8482
}
8583

8684
// We want to find two powers of 2 factors that produce a number
@@ -130,30 +128,6 @@ static void FindFactors(int size, int factor, out int x, out int y)
130128
Size = p2;
131129
}
132130

133-
/// <summary>
134-
/// Rounds up an <see cref="int"/> value to a power of 2.
135-
/// </summary>
136-
/// <param name="x">The input value to round up.</param>
137-
/// <returns>The smallest power of two greater than or equal to <paramref name="x"/>.</returns>
138-
[Pure]
139-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
140-
private static int RoundUpPowerOfTwo(int x)
141-
{
142-
#if NETCOREAPP3_1
143-
return 1 << (32 - BitOperations.LeadingZeroCount((uint)(x - 1)));
144-
#else
145-
x--;
146-
x |= x >> 1;
147-
x |= x >> 2;
148-
x |= x >> 4;
149-
x |= x >> 8;
150-
x |= x >> 16;
151-
x++;
152-
153-
return x;
154-
#endif
155-
}
156-
157131
/// <summary>
158132
/// Gets the shared <see cref="StringPool"/> instance.
159133
/// </summary>

0 commit comments

Comments
 (0)