Skip to content

Commit 0f99eae

Browse files
committed
Remove hashset allocation in token read
1 parent 16b9d57 commit 0f99eae

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

ValveKeyValue/ValveKeyValue/Deserialization/KeyValues1/KV1TokenReader.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Linq;
21
using System.Text;
32

43
namespace ValveKeyValue.Deserialization.KeyValues1
@@ -109,7 +108,7 @@ KVToken ReadComment()
109108
KVToken ReadCondition()
110109
{
111110
ReadChar(ConditionBegin);
112-
var text = ReadUntil(ConditionEnd);
111+
var text = ReadUntil(static (c) => c == ConditionEnd);
113112
ReadChar(ConditionEnd);
114113

115114
return new KVToken(KVTokenType.Condition, text);
@@ -118,7 +117,7 @@ KVToken ReadCondition()
118117
KVToken ReadInclusion()
119118
{
120119
ReadChar(InclusionMark);
121-
var term = ReadUntil(new[] { ' ', '\t' });
120+
var term = ReadUntil(static c => c is ' ' or '\t');
122121
var value = ReadStringRaw();
123122

124123
if (string.Equals(term, "include", StringComparison.Ordinal))
@@ -133,12 +132,11 @@ KVToken ReadInclusion()
133132
throw new InvalidDataException($"Unrecognized term after '#' symbol (line {Line}, column {Column})");
134133
}
135134

136-
string ReadUntil(params char[] terminators)
135+
string ReadUntil(Func<int, bool> isTerminator)
137136
{
138137
var escapeNext = false;
139138

140-
var integerTerminators = new HashSet<int>(terminators.Select(t => (int)t));
141-
while (!integerTerminators.Contains(Peek()) || escapeNext)
139+
while (escapeNext || !isTerminator(Peek()))
142140
{
143141
var next = Next();
144142

@@ -223,7 +221,7 @@ string ReadStringRaw()
223221
string ReadQuotedStringRaw()
224222
{
225223
ReadChar(QuotationMark);
226-
var text = ReadUntil(QuotationMark);
224+
var text = ReadUntil(static (c) => c == QuotationMark);
227225
ReadChar(QuotationMark);
228226
return text;
229227
}

0 commit comments

Comments
 (0)