tazel
A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.
Clonegit clone https://git.progmasoft.com/tazel
fix(cadre-celeste): clear SQLite pool on Load for Windows and lower AbiFingerprint complexity
- Commit
e425aeec1f51fabcd03c6d9c2f7f93dddeedc513- Author
- Leitwolf11 ·
- Parents
f6a3d2219b1a
Changes
.../AbiFingerprint.cs | 119 ++++++++++++--------- .../CadreCelesteStore.cs | 1 + 2 files changed, 69 insertions(+), 51 deletions(-) diff --git a/src/Progmasoft.Tazel.CadreCeleste/AbiFingerprint.cs b/src/Progmasoft.Tazel.CadreCeleste/AbiFingerprint.cs index 232bd59..5bafcb2 100644 --- a/src/Progmasoft.Tazel.CadreCeleste/AbiFingerprint.cs +++ b/src/Progmasoft.Tazel.CadreCeleste/AbiFingerprint.cs @@ -22,8 +22,7 @@ public static class AbiFingerprint public static ContentHash HashHeaderTokens(string source) { ArgumentNullException.ThrowIfNull(source); - var normalized = NormalizeHeaderTokens(source); - return ContentHash.FromString(normalized); + return ContentHash.FromString(NormalizeHeaderTokens(source)); } /// <summary> @@ -52,49 +51,58 @@ public static class AbiFingerprint while (i < source.Length) { - var ch = source[i]; - if (TrySkipComment(source, ref i)) - { - pendingSpace = sb.Length > 0 && sb[^1] != '\n'; - continue; - } + i = StepNormalize(source, i, sb, ref pendingSpace); + } - if (ch == '\r' || ch == '\n') - { - i++; - if (sb.Length > 0 && sb[^1] != '\n') - { - sb.Append('\n'); - } - - pendingSpace = false; - continue; - } + return sb.ToString().TrimEnd('\n', ' '); + } - if (char.IsWhiteSpace(ch)) - { - i++; - pendingSpace = sb.Length > 0 && sb[^1] != '\n'; - continue; - } + private static int StepNormalize(string source, int i, StringBuilder sb, ref bool pendingSpace) + { + var ch = source[i]; + if (TrySkipComment(source, ref i)) + { + pendingSpace = NeedsSpaceSeparator(sb); + return i; + } - if (pendingSpace) - { - sb.Append(' '); - pendingSpace = false; - } + if (ch is '\r' or '\n') + { + AppendNewlineIfNeeded(sb); + pendingSpace = false; + return i + 1; + } - if (ch is '"' or '\'') - { - CopyQuotedLiteral(source, ref i, ch, sb); - continue; - } + if (char.IsWhiteSpace(ch)) + { + pendingSpace = NeedsSpaceSeparator(sb); + return i + 1; + } - sb.Append(ch); - i++; + if (pendingSpace) + { + sb.Append(' '); + pendingSpace = false; } - return sb.ToString().TrimEnd('\n', ' '); + if (ch is '"' or '\'') + { + CopyQuotedLiteral(source, ref i, ch, sb); + return i; + } + + sb.Append(ch); + return i + 1; + } + + private static bool NeedsSpaceSeparator(StringBuilder sb) => sb.Length > 0 && sb[^1] != '\n'; + + private static void AppendNewlineIfNeeded(StringBuilder sb) + { + if (NeedsSpaceSeparator(sb)) + { + sb.Append('\n'); + } } private static bool TrySkipComment(string source, ref int i) @@ -106,30 +114,39 @@ public static class AbiFingerprint if (source[i + 1] == '/') { - i += 2; - while (i < source.Length && source[i] != '\n') - { - i++; - } - + i = SkipLineComment(source, i + 2); return true; } if (source[i + 1] == '*') { - i += 2; - while (i + 1 < source.Length && !(source[i] == '*' && source[i + 1] == '/')) - { - i++; - } - - i = i + 1 < source.Length ? i + 2 : source.Length; + i = SkipBlockComment(source, i + 2); return true; } return false; } + private static int SkipLineComment(string source, int i) + { + while (i < source.Length && source[i] != '\n') + { + i++; + } + + return i; + } + + private static int SkipBlockComment(string source, int i) + { + while (i + 1 < source.Length && !(source[i] == '*' && source[i + 1] == '/')) + { + i++; + } + + return i + 1 < source.Length ? i + 2 : source.Length; + } + private static void CopyQuotedLiteral(string source, ref int i, char quote, StringBuilder sb) { sb.Append(source[i++]); diff --git a/src/Progmasoft.Tazel.CadreCeleste/CadreCelesteStore.cs b/src/Progmasoft.Tazel.CadreCeleste/CadreCelesteStore.cs index 5d42437..3a4a11f 100644 --- a/src/Progmasoft.Tazel.CadreCeleste/CadreCelesteStore.cs +++ b/src/Progmasoft.Tazel.CadreCeleste/CadreCelesteStore.cs @@ -57,6 +57,7 @@ public static class CadreCelesteStore var (revision, green, red, pruned) = ReadMeta(conn); var edgesByNode = ReadEdges(conn); var nodes = ReadNodes(conn, edgesByNode); + SqliteConnection.ClearPool(conn); return new GraphSnapshot(revision, green, red, pruned, nodes); }