From d4fbdac5a22abc4d28ee2203dc8c5b312d7759fb Mon Sep 17 00:00:00 2001 From: Paul Harrington Date: Mon, 16 Feb 2015 10:52:52 -0800 Subject: [PATCH 1/2] PERF: In LargeEncodedText, use the BinarySearch extension method for integer arrays in instead of Array.BinarySearch --- src/Compilers/Core/Desktop/LargeEncodedText.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compilers/Core/Desktop/LargeEncodedText.cs b/src/Compilers/Core/Desktop/LargeEncodedText.cs index 89b1fc0c21a0e..a1daf50e4b54c 100644 --- a/src/Compilers/Core/Desktop/LargeEncodedText.cs +++ b/src/Compilers/Core/Desktop/LargeEncodedText.cs @@ -3,6 +3,7 @@ using System.IO; using System.Text; using System.Threading; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Text { @@ -109,7 +110,7 @@ private static bool IsBinary(char[] chunk) private int GetIndexFromPosition(int position) { // Binary search to find the chunk that contains the given position. - int idx = Array.BinarySearch(_chunkStartOffsets, position); + int idx = _chunkStartOffsets.BinarySearch(position); return idx >= 0 ? idx : (~idx - 1); } From c8c769cbdb05b8a7731cbfabd078a05e98570a67 Mon Sep 17 00:00:00 2001 From: Paul Harrington Date: Mon, 16 Feb 2015 10:50:06 -0800 Subject: [PATCH 2/2] PERF: Use the BinarySearch extension method for integer arrays instead of Array.BinarySearch --- .../Syntax/InternalSyntax/SyntaxList.WithLotsOfChildren.cs | 2 +- .../VisualBasic/Portable/Syntax/InternalSyntax/SyntaxList.vb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Syntax/InternalSyntax/SyntaxList.WithLotsOfChildren.cs b/src/Compilers/CSharp/Portable/Syntax/InternalSyntax/SyntaxList.WithLotsOfChildren.cs index 6f65f6bfc0641..b2c084dc326cb 100644 --- a/src/Compilers/CSharp/Portable/Syntax/InternalSyntax/SyntaxList.WithLotsOfChildren.cs +++ b/src/Compilers/CSharp/Portable/Syntax/InternalSyntax/SyntaxList.WithLotsOfChildren.cs @@ -52,7 +52,7 @@ public override int GetSlotOffset(int index) public override int FindSlotIndexContainingOffset(int offset) { Debug.Assert(offset >= 0 && offset < FullWidth); - int idx = Array.BinarySearch(_childOffsets, offset); + int idx = _childOffsets.BinarySearch(offset); return idx >= 0 ? idx : (~idx - 1); } diff --git a/src/Compilers/VisualBasic/Portable/Syntax/InternalSyntax/SyntaxList.vb b/src/Compilers/VisualBasic/Portable/Syntax/InternalSyntax/SyntaxList.vb index 1c05284d1370a..cccfb125a203d 100644 --- a/src/Compilers/VisualBasic/Portable/Syntax/InternalSyntax/SyntaxList.vb +++ b/src/Compilers/VisualBasic/Portable/Syntax/InternalSyntax/SyntaxList.vb @@ -466,7 +466,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ''' Public Overrides Function FindSlotIndexContainingOffset(offset As Integer) As Integer Debug.Assert(offset >= 0 AndAlso offset < FullWidth) - Dim idx = Array.BinarySearch(_childOffsets, offset) + Dim idx = _childOffsets.BinarySearch(offset) Return If(idx >= 0, idx, (Not idx) - 1) End Function