Utilities.cs 891 B

12345678910111213141516171819202122232425262728
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Diagnostics;
  5. using System.Runtime.CompilerServices;
  6. namespace System.Buffers
  7. {
  8. internal static class Utilities
  9. {
  10. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  11. internal static int SelectBucketIndex(int bufferSize)
  12. {
  13. Debug.Assert(bufferSize >= 0);
  14. uint bits = ((uint)bufferSize - 1) >> 4;
  15. return 32 - BitOps.LeadingZeroCount(bits);
  16. }
  17. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  18. internal static int GetMaxSizeForBucket(int binIndex)
  19. {
  20. int maxSize = 16 << binIndex;
  21. Debug.Assert(maxSize >= 0);
  22. return maxSize;
  23. }
  24. }
  25. }