removed debug code and fixed some bugs
This commit is contained in:
parent
f3106769d9
commit
c4ab4028ae
@ -16,9 +16,6 @@ public class SaveParserEU4
|
||||
private readonly ObjectPool<StringBuilder> _stringBuilderPool;
|
||||
private ISearchExpression? _searchExprCurrent;
|
||||
|
||||
public int SBPoolGetCount = 0;
|
||||
public int SBPoolReturnCount = 0;
|
||||
|
||||
/// <param name="savefile">
|
||||
/// Uncompressed stream of <c>gamestate</c> file which can be extracted from save archive
|
||||
/// </param>
|
||||
@ -50,7 +47,6 @@ public class SaveParserEU4
|
||||
throw new Exception($"Invalid gamestate header. Expected '{expectedHeader}', got '{headStr}'.");
|
||||
|
||||
StringBuilder strb = _stringBuilderPool.Get();
|
||||
SBPoolGetCount++;
|
||||
int line = 2;
|
||||
int column = 0;
|
||||
bool isQuoteOpen = false;
|
||||
@ -80,7 +76,6 @@ public class SaveParserEU4
|
||||
value = strb,
|
||||
};
|
||||
strb = _stringBuilderPool.Get();
|
||||
SBPoolGetCount++;
|
||||
isStrInQuotes = false;
|
||||
return true;
|
||||
}
|
||||
@ -95,7 +90,6 @@ public class SaveParserEU4
|
||||
if (TryCompleteStringToken())
|
||||
yield return strToken;
|
||||
_stringBuilderPool.Return(strb);
|
||||
SBPoolReturnCount++;
|
||||
yield break;
|
||||
case '\"':
|
||||
isQuoteOpen = !isQuoteOpen;
|
||||
@ -150,7 +144,6 @@ public class SaveParserEU4
|
||||
}
|
||||
|
||||
_stringBuilderPool.Return(strb);
|
||||
SBPoolReturnCount++;
|
||||
}
|
||||
|
||||
|
||||
@ -161,9 +154,12 @@ public class SaveParserEU4
|
||||
switch (tok.type)
|
||||
{
|
||||
case TokenType.StringOrNumber:
|
||||
string tokStr = tok.value!.ToString();
|
||||
// string values can be empty
|
||||
if(tok.value!.Length == 0)
|
||||
return string.Empty;
|
||||
|
||||
string tokStr = tok.value.ToString();
|
||||
_stringBuilderPool.Return(tok.value);
|
||||
SBPoolReturnCount++;
|
||||
if (tokStr[0] != '-' && !char.IsDigit(tokStr[0]))
|
||||
return tokStr;
|
||||
if (tokStr.Contains('.') && double.TryParse(tokStr, out double d))
|
||||
@ -194,7 +190,6 @@ public class SaveParserEU4
|
||||
return true;
|
||||
case TokenType.StringOrNumber:
|
||||
_stringBuilderPool.Return(tok.value!);
|
||||
SBPoolReturnCount++;
|
||||
return true;
|
||||
case TokenType.Equals:
|
||||
return true;
|
||||
@ -218,7 +213,6 @@ public class SaveParserEU4
|
||||
else if (tok.type == TokenType.StringOrNumber)
|
||||
{
|
||||
_stringBuilderPool.Return(tok.value!);
|
||||
SBPoolReturnCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -302,7 +296,6 @@ public class SaveParserEU4
|
||||
{
|
||||
SkipValue();
|
||||
_stringBuilderPool.Return(keySB);
|
||||
SBPoolReturnCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -315,7 +308,6 @@ public class SaveParserEU4
|
||||
|
||||
string keyStr = keySB.ToString();
|
||||
_stringBuilderPool.Return(keySB);
|
||||
SBPoolReturnCount++;
|
||||
if (!dict.TryGetValue(keyStr, out var list))
|
||||
{
|
||||
list = new List<object>();
|
||||
|
||||
@ -109,7 +109,7 @@ public partial class Program
|
||||
}
|
||||
finally
|
||||
{
|
||||
GC.Collect();
|
||||
GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, false, true);
|
||||
}
|
||||
|
||||
return await ReturnResponseJson(ctx, meta);
|
||||
|
||||
@ -55,21 +55,6 @@ public static partial class Program
|
||||
|
||||
try
|
||||
{
|
||||
Stopwatch stopwatch = new();
|
||||
using var save = File.OpenRead("data/gamestate");
|
||||
stopwatch.Start();
|
||||
var parser = new SaveParserEU4(save, SearchExpressionCompiler.Compile("saved_event_target"));
|
||||
var result = parser.Parse();
|
||||
stopwatch.Stop();
|
||||
using (var resultFile = File.OpenWrite("data/parsed.json"))
|
||||
{
|
||||
JsonSerializer.Serialize(resultFile, result, _saveSerializerOptions);
|
||||
}
|
||||
Console.WriteLine($"get: {parser.SBPoolGetCount} return: {parser.SBPoolReturnCount} " +
|
||||
$"delta: {parser.SBPoolGetCount - parser.SBPoolReturnCount}");
|
||||
Console.WriteLine(stopwatch.Elapsed);
|
||||
return;
|
||||
|
||||
// config
|
||||
if (!File.Exists(_configPath))
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user