From 244c960de2fdbddc3c0581f9c5ca74addfb730cc Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 26 Jan 2026 17:19:00 -0500 Subject: [PATCH 1/2] Use IndexOfAny in Console's TermInfo Not a perf sensitive thing, just a bit simpler --- src/libraries/System.Console/src/System/TermInfo.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.Console/src/System/TermInfo.cs b/src/libraries/System.Console/src/System/TermInfo.cs index 0241e77bf43fca..7a369d63eaf1c4 100644 --- a/src/libraries/System.Console/src/System/TermInfo.cs +++ b/src/libraries/System.Console/src/System/TermInfo.cs @@ -161,19 +161,12 @@ private static string EvaluateInternal( // (with a ':' used in front of flags to help differentiate from binary operations, as flags can // include '-' and '+'). While above we've special-cased common usage (e.g. %d, %s), // for more complicated expressions we delegate to printf. - int printfEnd = pos; - for (; printfEnd < format.Length; printfEnd++) // find the end of the printf format string - { - char ec = format[printfEnd]; - if (ec == 'd' || ec == 'o' || ec == 'x' || ec == 'X' || ec == 's') - { - break; - } - } - if (printfEnd >= format.Length) + int printfEnd = format.AsSpan(pos).IndexOfAny("doxXs"); // find the end of the printf format string + if (printfEnd < 0) { throw new InvalidOperationException(SR.IO_TermInfoInvalid); } + printfEnd += pos; string printfFormat = format.Substring(pos - 1, printfEnd - pos + 2); // extract the format string if (printfFormat.Length > 1 && printfFormat[1] == ':') { From 8f390f74302bdf0fa60769598de7b328367513b6 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 26 Jan 2026 21:17:40 -0500 Subject: [PATCH 2/2] Update src/libraries/System.Console/src/System/TermInfo.cs Co-authored-by: Miha Zupan --- src/libraries/System.Console/src/System/TermInfo.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libraries/System.Console/src/System/TermInfo.cs b/src/libraries/System.Console/src/System/TermInfo.cs index 7a369d63eaf1c4..32e4aa1cbfcab5 100644 --- a/src/libraries/System.Console/src/System/TermInfo.cs +++ b/src/libraries/System.Console/src/System/TermInfo.cs @@ -166,8 +166,7 @@ private static string EvaluateInternal( { throw new InvalidOperationException(SR.IO_TermInfoInvalid); } - printfEnd += pos; - string printfFormat = format.Substring(pos - 1, printfEnd - pos + 2); // extract the format string + string printfFormat = format.Substring(pos - 1, printfEnd + 2); // extract the format string if (printfFormat.Length > 1 && printfFormat[1] == ':') { printfFormat = printfFormat.Remove(1, 1);