@@ -144,14 +144,9 @@ public static bool EncodeLiteralHeaderFieldWithoutNameReference(string name, str
144
144
/// <summary>
145
145
/// Encodes a Literal Header Field Without Name Reference, building the value by concatenating a collection of strings with separators.
146
146
/// </summary>
147
- public static bool EncodeLiteralHeaderFieldWithoutNameReference ( string name , ReadOnlySpan < string > values , string valueSeparator , Span < byte > destination , out int bytesWritten )
147
+ public static bool EncodeLiteralHeaderFieldWithoutNameReference ( string name , ReadOnlySpan < string > values , byte [ ] separator , Encoding ? valueEncoding , Span < byte > destination , out int bytesWritten )
148
148
{
149
- return EncodeLiteralHeaderFieldWithoutNameReference ( name , values , valueSeparator , valueEncoding : null , destination , out bytesWritten ) ;
150
- }
151
-
152
- public static bool EncodeLiteralHeaderFieldWithoutNameReference ( string name , ReadOnlySpan < string > values , string valueSeparator , Encoding ? valueEncoding , Span < byte > destination , out int bytesWritten )
153
- {
154
- if ( EncodeNameString ( name , destination , out int nameLength ) && EncodeValueString ( values , valueSeparator , valueEncoding , destination . Slice ( nameLength ) , out int valueLength ) )
149
+ if ( EncodeNameString ( name , destination , out int nameLength ) && EncodeValueString ( values , separator , valueEncoding , destination . Slice ( nameLength ) , out int valueLength ) )
155
150
{
156
151
bytesWritten = nameLength + valueLength ;
157
152
return true ;
@@ -222,12 +217,7 @@ private static bool EncodeValueString(string s, Encoding? valueEncoding, Span<by
222
217
/// <summary>
223
218
/// Encodes a value by concatenating a collection of strings, separated by a separator string.
224
219
/// </summary>
225
- public static bool EncodeValueString ( ReadOnlySpan < string > values , string ? separator , Span < byte > buffer , out int length )
226
- {
227
- return EncodeValueString ( values , separator , valueEncoding : null , buffer , out length ) ;
228
- }
229
-
230
- public static bool EncodeValueString ( ReadOnlySpan < string > values , string ? separator , Encoding ? valueEncoding , Span < byte > buffer , out int length )
220
+ public static bool EncodeValueString ( ReadOnlySpan < string > values , byte [ ] ? separator , Encoding ? valueEncoding , Span < byte > buffer , out int length )
231
221
{
232
222
if ( values . Length == 1 )
233
223
{
@@ -243,18 +233,18 @@ public static bool EncodeValueString(ReadOnlySpan<string> values, string? separa
243
233
if ( buffer . Length > 0 )
244
234
{
245
235
Debug . Assert ( separator != null ) ;
246
- int valueLength ;
236
+ Debug . Assert ( Ascii . IsValid ( separator ) ) ;
237
+ int valueLength = separator . Length * ( values . Length - 1 ) ;
238
+
247
239
if ( valueEncoding is null || ReferenceEquals ( valueEncoding , Encoding . Latin1 ) )
248
240
{
249
- valueLength = separator . Length * ( values . Length - 1 ) ;
250
241
foreach ( string part in values )
251
242
{
252
243
valueLength += part . Length ;
253
244
}
254
245
}
255
246
else
256
247
{
257
- valueLength = valueEncoding . GetByteCount ( separator ) * ( values . Length - 1 ) ;
258
248
foreach ( string part in values )
259
249
{
260
250
valueLength += valueEncoding . GetByteCount ( part ) ;
@@ -275,7 +265,7 @@ public static bool EncodeValueString(ReadOnlySpan<string> values, string? separa
275
265
276
266
for ( int i = 1 ; i < values . Length ; i ++ )
277
267
{
278
- EncodeValueStringPart ( separator , buffer ) ;
268
+ separator . CopyTo ( buffer ) ;
279
269
buffer = buffer . Slice ( separator . Length ) ;
280
270
281
271
value = values [ i ] ;
@@ -290,8 +280,8 @@ public static bool EncodeValueString(ReadOnlySpan<string> values, string? separa
290
280
291
281
for ( int i = 1 ; i < values . Length ; i ++ )
292
282
{
293
- written = valueEncoding . GetBytes ( separator , buffer ) ;
294
- buffer = buffer . Slice ( written ) ;
283
+ separator . CopyTo ( buffer ) ;
284
+ buffer = buffer . Slice ( separator . Length ) ;
295
285
296
286
written = valueEncoding . GetBytes ( values [ i ] , buffer ) ;
297
287
buffer = buffer . Slice ( written ) ;
0 commit comments