/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Dependencies/Collections/Extensions/MemoryExtensions.cs
45 строк
1 KB
Tomáš Matoušek
Refactoring of extension methods in source packages (#78620) - take 2 (#78894)
26 июн 2025, 18:42
Не верифицирован
26 июн 2025, 18:42
05fc006
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable enable namespace System { /// <remarks> /// Defines polyfill methods and overloads or alternative names of existing Span related methods defined in System. /// </remarks> internal static class RoslynMemoryExtensions { /// <summary> /// Variant of <see cref="System.MemoryExtensions.BinarySearch{T, TComparer}(ReadOnlySpan{T}, T, TComparer)"/>. /// </summary> public static int BinarySearch<TElement, TValue>(this ReadOnlySpan<TElement> span, TValue value, Func<TElement, TValue, int> comparer) { int low = 0; int high = span.Length - 1; while (low <= high) { int middle = low + ((high - low) >> 1); int comparison = comparer(span[middle], value); if (comparison == 0) { return middle; } if (comparison > 0) { high = middle - 1; } else { low = middle + 1; } } return ~low; } } }