From 3dd27eb134d9c314547446d984660ad1a0d666fd Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Thu, 5 Dec 2024 19:51:28 +0100 Subject: [PATCH 1/2] Speedup another scanner loop --- src/Sdk/AzurePipelines/AzureDevops.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Sdk/AzurePipelines/AzureDevops.cs b/src/Sdk/AzurePipelines/AzureDevops.cs index 306ffb81525..b52a8f15cea 100644 --- a/src/Sdk/AzurePipelines/AzureDevops.cs +++ b/src/Sdk/AzurePipelines/AzureDevops.cs @@ -631,6 +631,26 @@ public static string RelativeTo(string cwd, string filename) { private static ((int, int)[], Dictionary<(int, int), int>) CreateIdxMapping(TemplateToken token) { if(token is LiteralToken lit && lit.RawData != null) { +#if HAVE_YAML_DOTNET_FORK + var praw = lit.ToString(); + + YamlDotNet.Core.Tokens.Scalar found = null; + var scanner = new YamlDotNet.Core.Scanner(new StringReader(praw), true); + try { + while(scanner.MoveNext() && !(scanner.Current is YamlDotNet.Core.Tokens.Error)) { + if(scanner.Current is YamlDotNet.Core.Tokens.Scalar s) { + found = s; + break; + } + } + } catch { + + } + + if(found != null) { + return (found.Mapping.Select(m => ((int)(m.Line - 1 + token.Line), m.Line == 1 ? (int)(token.Column - 1 + m.Column) : (int)m.Column)).ToArray(), found.RMapping.ToDictionary(m => ((int)(m.Key.Line - 1 + token.Line), (int)m.Key.Line == 1 ? (int)(token.Column - 1 + m.Key.Column) : (int)m.Key.Column), m => m.Value)); + } +#else var rand = new Random(); string C = "CX"; while(lit.RawData.Contains(C)) { @@ -675,6 +695,7 @@ private static ((int, int)[], Dictionary<(int, int), int>) CreateIdxMapping(Temp } return (mapping, rmapping); } +#endif return (null, null); } From 03047a9b7bc887019cc971fa5a02be1729999ad0 Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Thu, 5 Dec 2024 19:57:14 +0100 Subject: [PATCH 2/2] fix --- src/Sdk/AzurePipelines/AzureDevops.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sdk/AzurePipelines/AzureDevops.cs b/src/Sdk/AzurePipelines/AzureDevops.cs index b52a8f15cea..8a4364cde6f 100644 --- a/src/Sdk/AzurePipelines/AzureDevops.cs +++ b/src/Sdk/AzurePipelines/AzureDevops.cs @@ -694,8 +694,8 @@ private static ((int, int)[], Dictionary<(int, int), int>) CreateIdxMapping(Temp column++; } return (mapping, rmapping); - } #endif + } return (null, null); }