Skip to content

Commit a3fbfa3

Browse files
committed
Remove unnecessary extensions
1 parent d172bd6 commit a3fbfa3

File tree

8 files changed

+17
-48
lines changed

8 files changed

+17
-48
lines changed

src/Compilers/CSharp/Portable/CommandLine/CommandLineDiagnosticFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal string RelativizeNormalizedPath(string normalizedPath)
7171
if (PathUtilities.IsSameDirectoryOrChildOf(normalizedDirectory, normalizedBaseDirectory))
7272
{
7373
return normalizedPath.Substring(
74-
PathUtilities.IsDirectorySeparator(normalizedBaseDirectory.Last())
74+
PathUtilities.IsDirectorySeparator(normalizedBaseDirectory[^1])
7575
? normalizedBaseDirectory.Length
7676
: normalizedBaseDirectory.Length + 1);
7777
}

src/Compilers/CSharp/Portable/Syntax/SyntaxNormalizer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,8 @@ private static bool NeedsSeparator(SyntaxToken token, SyntaxToken next)
927927
}
928928
else if (token.Width > 1 && next.Width > 1)
929929
{
930-
var tokenLastChar = token.Text.Last();
931-
var nextFirstChar = next.Text.First();
930+
var tokenLastChar = token.Text[^1];
931+
var nextFirstChar = next.Text[0];
932932
if (tokenLastChar == nextFirstChar && TokenCharacterCanBeDoubled(tokenLastChar))
933933
{
934934
return true;
@@ -1251,7 +1251,7 @@ private static bool EndsInLineBreak(SyntaxTrivia trivia)
12511251
if (trivia.Kind() == SyntaxKind.PreprocessingMessageTrivia || trivia.Kind() == SyntaxKind.DisabledTextTrivia)
12521252
{
12531253
var text = trivia.ToFullString();
1254-
return text.Length > 0 && SyntaxFacts.IsNewLine(text.Last());
1254+
return text.Length > 0 && SyntaxFacts.IsNewLine(text[^1]);
12551255
}
12561256

12571257
if (trivia.HasStructure)

src/Compilers/Core/Portable/InternalUtilities/Hash.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System;
68
using System.Collections.Generic;
79
using System.Collections.Immutable;

src/Compilers/Core/Portable/InternalUtilities/RoslynString.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System.Diagnostics.CodeAnalysis;
68

79
namespace Roslyn.Utilities

src/Compilers/Core/Portable/InternalUtilities/StringExtensions.cs

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System;
68
using System.Collections.Generic;
79
using System.Collections.Immutable;
@@ -13,6 +15,8 @@ namespace Roslyn.Utilities
1315
{
1416
internal static class StringExtensions
1517
{
18+
private static readonly Func<char, char> s_toLower = char.ToLower;
19+
private static readonly Func<char, char> s_toUpper = char.ToUpper;
1620
private static ImmutableArray<string> s_lazyNumerals;
1721
private static UTF8Encoding? s_lazyUtf8;
1822

@@ -30,19 +34,7 @@ internal static string GetNumeral(int number)
3034
}
3135

3236
public static string Join(this IEnumerable<string?> source, string separator)
33-
{
34-
if (source == null)
35-
{
36-
throw new ArgumentNullException(nameof(source));
37-
}
38-
39-
if (separator == null)
40-
{
41-
throw new ArgumentNullException(nameof(separator));
42-
}
43-
44-
return string.Join(separator, source);
45-
}
37+
=> string.Join(separator, source);
4638

4739
public static bool LooksLikeInterfaceName(this string name)
4840
{
@@ -54,9 +46,6 @@ public static bool LooksLikeTypeParameterName(this string name)
5446
return name.Length >= 3 && name[0] == 'T' && char.IsUpper(name[1]) && char.IsLower(name[2]);
5547
}
5648

57-
private static readonly Func<char, char> s_toLower = char.ToLower;
58-
private static readonly Func<char, char> s_toUpper = char.ToUpper;
59-
6049
[return: NotNullIfNotNull(parameterName: nameof(shortName))]
6150
public static string? ToPascalCase(
6251
this string? shortName,
@@ -228,32 +217,6 @@ internal static string Unquote(this string arg, out bool quoted)
228217
}
229218
}
230219

231-
// String isn't IEnumerable<char> in the current Portable profile.
232-
internal static char First(this string arg)
233-
{
234-
return arg[0];
235-
}
236-
237-
// String isn't IEnumerable<char> in the current Portable profile.
238-
internal static char Last(this string arg)
239-
{
240-
return arg[arg.Length - 1];
241-
}
242-
243-
// String isn't IEnumerable<char> in the current Portable profile.
244-
internal static bool All(this string arg, Predicate<char> predicate)
245-
{
246-
foreach (char c in arg)
247-
{
248-
if (!predicate(c))
249-
{
250-
return false;
251-
}
252-
}
253-
254-
return true;
255-
}
256-
257220
public static int GetCaseInsensitivePrefixLength(this string string1, string string2)
258221
{
259222
int x = 0;

src/Compilers/Core/Portable/SpecialTypeExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System;
68
using System.Diagnostics;
7-
using Roslyn.Utilities;
89

910
namespace Microsoft.CodeAnalysis
1011
{

src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.CodeShapeAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private bool OnDisabledTextTrivia(SyntaxTrivia trivia, int index)
310310
if (trivia.IsKind(SyntaxKind.DisabledTextTrivia))
311311
{
312312
var triviaString = trivia.ToString();
313-
if (!string.IsNullOrEmpty(triviaString) && SyntaxFacts.IsNewLine(triviaString.Last()))
313+
if (!string.IsNullOrEmpty(triviaString) && SyntaxFacts.IsNewLine(triviaString[^1]))
314314
{
315315
ResetStateAfterNewLine(index);
316316
}

src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Diagnostics;
6+
using System.Linq;
67
using Microsoft.CodeAnalysis;
78
using Microsoft.CodeAnalysis.Formatting;
89
using Microsoft.CodeAnalysis.Shared.Extensions;

0 commit comments

Comments
 (0)