Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup another scanner loop #463

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Sdk/AzurePipelines/AzureDevops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -674,6 +694,7 @@ private static ((int, int)[], Dictionary<(int, int), int>) CreateIdxMapping(Temp
column++;
}
return (mapping, rmapping);
#endif
}
return (null, null);
}
Expand Down
Loading