From 75cc1dc5938a60cf6b4bee95f1a8e54e4c143633 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Sat, 8 Nov 2025 13:53:41 +0000 Subject: [PATCH] perf: delay `string.Replace` call --- Src/CSharpier.Cli/CommandLineFormatter.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Src/CSharpier.Cli/CommandLineFormatter.cs b/Src/CSharpier.Cli/CommandLineFormatter.cs index 2220c09d0..3b7de1c51 100644 --- a/Src/CSharpier.Cli/CommandLineFormatter.cs +++ b/Src/CSharpier.Cli/CommandLineFormatter.cs @@ -228,7 +228,7 @@ CancellationToken cancellationToken async Task FormatFile( string actualFilePath, - string originalFilePath, + string? originalFilePath = null, bool warnForUnsupported = false ) { @@ -247,6 +247,11 @@ async Task FormatFile( cancellationToken ); + originalFilePath ??= actualFilePath.Replace( + directoryOrFilePath, + originalDirectoryOrFile + ); + if (printerOptions is { Formatter: not Formatter.Unknown }) { printerOptions.IncludeGenerated = commandLineOptions.IncludeGenerated; @@ -298,9 +303,7 @@ await FormatPhysicalFile( "*.*", SearchOption.AllDirectories ) - .Select(o => - FormatFile(o, o.Replace(directoryOrFilePath, originalDirectoryOrFile)) - ) + .Select(o => FormatFile(o)) .ToArray(); try {