@@ -20,6 +20,7 @@ public KV1TokenReader(TextReader textReader, KVSerializerOptions options) : base
2020 this . options = options ;
2121 }
2222
23+ readonly StringBuilder sb = new ( ) ;
2324 readonly KVSerializerOptions options ;
2425
2526 public KVToken ReadNextToken ( )
@@ -69,8 +70,6 @@ KVToken ReadComment()
6970 {
7071 ReadChar ( CommentBegin ) ;
7172
72- var sb = new StringBuilder ( ) ;
73-
7473 // Some keyvalues implementations have a bug where only a single slash is needed for a comment
7574 // If the file ends with a single slash then we have an empty comment, bail out
7675 if ( ! TryGetNext ( out var next ) )
@@ -102,6 +101,7 @@ KVToken ReadComment()
102101 }
103102
104103 var text = sb . ToString ( ) ;
104+ sb . Clear ( ) ;
105105
106106 return new KVToken ( KVTokenType . Comment , text ) ;
107107 }
@@ -135,7 +135,6 @@ KVToken ReadInclusion()
135135
136136 string ReadUntil ( params char [ ] terminators )
137137 {
138- var sb = new StringBuilder ( ) ;
139138 var escapeNext = false ;
140139
141140 var integerTerminators = new HashSet < int > ( terminators . Select ( t => ( int ) t ) ) ;
@@ -178,6 +177,7 @@ string ReadUntil(params char[] terminators)
178177 }
179178
180179 var result = sb . ToString ( ) ;
180+ sb . Clear ( ) ;
181181
182182 // Valve bug-for-bug compatibility with tier1 KeyValues/CUtlBuffer: an invalid escape sequence is a null byte which
183183 // causes the text to be trimmed to the point of that null byte.
@@ -190,8 +190,6 @@ string ReadUntil(params char[] terminators)
190190
191191 string ReadUntilWhitespaceOrQuote ( )
192192 {
193- var sb = new StringBuilder ( ) ;
194-
195193 while ( true )
196194 {
197195 var next = Peek ( ) ;
@@ -203,7 +201,10 @@ string ReadUntilWhitespaceOrQuote()
203201 sb . Append ( Next ( ) ) ;
204202 }
205203
206- return sb . ToString ( ) ;
204+ var result = sb . ToString ( ) ;
205+ sb . Clear ( ) ;
206+
207+ return result ;
207208 }
208209
209210 string ReadStringRaw ( )
0 commit comments