From 5de3a94a46fd1b45893abbc354a5319ead0deb66 Mon Sep 17 00:00:00 2001 From: Timerix Date: Sat, 5 Apr 2025 09:42:39 +0500 Subject: [PATCH] fixed bugs related to index check and gc --- ParadoxSaveParser.Lib/SaveParserEU4.cs | 20 +++++++++++++++---- ParadoxSaveParser.Lib/SearchExpression.cs | 3 ++- .../Program.RequestHandlers.cs | 2 +- ParadoxSaveParser.WebAPI/Program.cs | 1 - 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ParadoxSaveParser.Lib/SaveParserEU4.cs b/ParadoxSaveParser.Lib/SaveParserEU4.cs index 22a4998..005f262 100644 --- a/ParadoxSaveParser.Lib/SaveParserEU4.cs +++ b/ParadoxSaveParser.Lib/SaveParserEU4.cs @@ -191,8 +191,6 @@ public class SaveParserEU4 case TokenType.StringOrNumber: _stringBuilderPool.Return(tok.value!); return true; - case TokenType.Equals: - return true; case TokenType.BracketClose: return false; default: @@ -232,13 +230,26 @@ public class SaveParserEU4 private List ParseList() { List list = new(); - while (true) + for (int i = 0; ; i++) { if (!_tokens.MoveNext()) throw new Exception("Unexpected end of file"); + + ISearchExpression? searchExprNext = null; + if (_searchExprCurrent != null + && !_searchExprCurrent.DoesMatch(new SearchArgs(i, string.Empty), out searchExprNext)) + { + if(!SkipValue()) + break; + continue; + } + var searchExprPrev = _searchExprCurrent; + _searchExprCurrent = searchExprNext; object? value = ParseValue(); + _searchExprCurrent = searchExprPrev; if (value is null) break; + list.Add(value); } @@ -294,7 +305,8 @@ public class SaveParserEU4 if (_searchExprCurrent != null && !_searchExprCurrent.DoesMatch(new SearchArgs(localIndex, keySB), out searchExprNext)) { - SkipValue(); + if(!SkipValue()) + throw new UnexpectedTokenException(_tokens.Current.Value); _stringBuilderPool.Return(keySB); continue; } diff --git a/ParadoxSaveParser.Lib/SearchExpression.cs b/ParadoxSaveParser.Lib/SearchExpression.cs index a3c66a7..afa4b46 100644 --- a/ParadoxSaveParser.Lib/SearchExpression.cs +++ b/ParadoxSaveParser.Lib/SearchExpression.cs @@ -86,7 +86,8 @@ public static class SearchExpressionCompiler ReadOnlySpan remaining = default; if (partBeforePointLength < query.Length) remaining = query.Slice(partBeforePointLength + 1); - if (part is "*") return new AnyMatchExpression(remaining.IsEmpty ? null : Compile(remaining)); + if (part is "*") + return new AnyMatchExpression(remaining.IsEmpty ? null : Compile(remaining)); for (int j = 0; j < part.Length; j++) if (CharEqualsAndNotEscaped('*', part, j)) diff --git a/ParadoxSaveParser.WebAPI/Program.RequestHandlers.cs b/ParadoxSaveParser.WebAPI/Program.RequestHandlers.cs index 0c9fcf3..373b5c4 100644 --- a/ParadoxSaveParser.WebAPI/Program.RequestHandlers.cs +++ b/ParadoxSaveParser.WebAPI/Program.RequestHandlers.cs @@ -109,7 +109,7 @@ public partial class Program } finally { - GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, false, true); + GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true); } return await ReturnResponseJson(ctx, meta); diff --git a/ParadoxSaveParser.WebAPI/Program.cs b/ParadoxSaveParser.WebAPI/Program.cs index 9bab2bc..ace24e0 100644 --- a/ParadoxSaveParser.WebAPI/Program.cs +++ b/ParadoxSaveParser.WebAPI/Program.cs @@ -12,7 +12,6 @@ global using Directory = DTLib.Filesystem.Directory; global using File = DTLib.Filesystem.File; global using Path = DTLib.Filesystem.Path; using System.Collections.Concurrent; -using System.Diagnostics; using System.IO; using System.Text.Encodings.Web; using DTLib.Dtsod;