Skip to content

Commit

Permalink
PR feedback from dotnet#10756
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzngard committed Aug 29, 2024
1 parent 3179c68 commit 54d5a07
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ImmutableArray<TagHelperDescriptor> GetValues(ProjectId projectKey, int r
return [];
}

using var _ = ArrayBuilderPool<TagHelperDescriptor>.GetPooledObject(out var builder);
using var builder = new PooledArrayBuilder<TagHelperDescriptor>();
foreach (var checksum in cachedChecksums)
{
var value = TryGet(checksum);
Expand All @@ -41,7 +41,7 @@ public ImmutableArray<TagHelperDescriptor> GetValues(ProjectId projectKey, int r
builder.Add(value);
}

return builder.ToImmutableArray();
return builder.DrainToImmutable();
}

public async ValueTask<DeltaResult> GetDeltaAsync(Project project, int? lastResultIdNullable, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ namespace Microsoft.AspNetCore.Razor;

internal static class RazorProjectInfoHelpers
{
private static readonly StringComparison s_stringComparison;

static RazorProjectInfoHelpers()
{
s_stringComparison = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? StringComparison.Ordinal
: StringComparison.OrdinalIgnoreCase;
}

public static RazorProjectInfo? TryConvert(
Project project,
string projectPath,
Expand Down Expand Up @@ -181,7 +172,7 @@ public static ImmutableArray<DocumentSnapshotHandle> GetDocuments(Project projec
private static string GetTargetPath(string documentFilePath, string normalizedProjectPath)
{
var targetFilePath = FilePathNormalizer.Normalize(documentFilePath);
if (targetFilePath.StartsWith(normalizedProjectPath, s_stringComparison))
if (targetFilePath.StartsWith(normalizedProjectPath, FilePathComparison.Instance))
{
// Make relative
targetFilePath = documentFilePath[normalizedProjectPath.Length..];
Expand All @@ -197,12 +188,12 @@ private static bool TryGetFileKind(string filePath, [NotNullWhen(true)] out stri
{
var extension = Path.GetExtension(filePath);

if (extension.Equals(".cshtml", s_stringComparison))
if (extension.Equals(".cshtml", FilePathComparison.Instance))
{
fileKind = FileKinds.Legacy;
return true;
}
else if (extension.Equals(".razor", s_stringComparison))
else if (extension.Equals(".razor", FilePathComparison.Instance))
{
fileKind = FileKinds.GetComponentFileKindFromFilePath(filePath);
return true;
Expand All @@ -228,7 +219,7 @@ private static bool TryGetRazorFileName(string? filePath, [NotNullWhen(true)] ou

// Generated files have a path like: virtualcsharp-razor:///e:/Scratch/RazorInConsole/Goo.cshtml__virtual.cs
if (filePath.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) &&
(filePath.EndsWith(generatedRazorExtension, s_stringComparison) || filePath.EndsWith(generatedCshtmlExtension, s_stringComparison)))
(filePath.EndsWith(generatedRazorExtension, FilePathComparison.Instance) || filePath.EndsWith(generatedCshtmlExtension, FilePathComparison.Instance)))
{
// Go through the file path normalizer because it also does Uri decoding, and we're converting from a Uri to a path
// but "new Uri(filePath).LocalPath" seems wasteful
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Threading.Tasks;
using MessagePack.Resolvers;
using MessagePack;
using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Resolvers;
using System.Buffers;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MessagePack;
using MessagePack.Resolvers;
using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Resolvers;

namespace Microsoft.AspNetCore.Razor.Serialization;

Expand All @@ -31,6 +31,9 @@ public static void SerializeTo<T>(T instance, Stream stream)
public static T? DeserializeFrom<T>(ReadOnlyMemory<byte> buffer)
=> MessagePackSerializer.Deserialize<T>(buffer, s_options);

public static T? DeserializeFrom<T>(ReadOnlySequence<byte> buffer)
=> MessagePackSerializer.Deserialize<T>(buffer, s_options);

public static T? DeserializeFrom<T>(Stream stream)
=> MessagePackSerializer.Deserialize<T>(stream, s_options);

Expand Down

0 comments on commit 54d5a07

Please sign in to comment.