fix: address code quality review findings for batch 1

- SubjectsCollide: split tokens once upfront instead of O(n²) TokenAt calls
- NatsHeaderParser: manual digit accumulation avoids string allocation and overflow
- NatsHeaders: use IReadOnlyDictionary for Headers, immutable Invalid sentinel
- PermissionLruCache: add missing Count property
This commit is contained in:
Joseph Doherty
2026-02-23 00:40:14 -05:00
parent dddced444e
commit 0ec5583422
3 changed files with 34 additions and 16 deletions

View File

@@ -172,11 +172,13 @@ public static class SubjectMatch
if (lit2 && !lit1)
return MatchLiteral(subj2, subj1);
// Both have wildcards
int n1 = NumTokens(subj1);
int n2 = NumTokens(subj2);
bool hasFwc1 = subj1.Contains('>');
bool hasFwc2 = subj2.Contains('>');
// Both have wildcards — split once to avoid O(n²) TokenAt calls
var tokens1 = subj1.Split(Sep);
var tokens2 = subj2.Split(Sep);
int n1 = tokens1.Length;
int n2 = tokens2.Length;
bool hasFwc1 = tokens1[^1] == ">";
bool hasFwc2 = tokens2[^1] == ">";
if (!hasFwc1 && !hasFwc2 && n1 != n2)
return false;
@@ -188,9 +190,7 @@ public static class SubjectMatch
int stop = Math.Min(n1, n2);
for (int i = 0; i < stop; i++)
{
var t1 = TokenAt(subj1, i);
var t2 = TokenAt(subj2, i);
if (!TokensCanMatch(t1, t2))
if (!TokensCanMatch(tokens1[i], tokens2[i]))
return false;
}
return true;