@@ -17,29 +17,30 @@ internal JsonSeparatorNamingPolicy(bool lowercase, char separator) =>
17
17
public sealed override string ConvertName ( string name )
18
18
{
19
19
// Rented buffer 20% longer that the input.
20
- int bufferLength = ( 12 * name . Length ) / 10 ;
21
- char [ ] ? buffer = bufferLength > JsonConstants . StackallocCharThreshold
22
- ? ArrayPool < char > . Shared . Rent ( bufferLength )
20
+ int rentedBufferLength = ( 12 * name . Length ) / 10 ;
21
+ char [ ] ? rentedBuffer = rentedBufferLength > JsonConstants . StackallocCharThreshold
22
+ ? ArrayPool < char > . Shared . Rent ( rentedBufferLength )
23
23
: null ;
24
24
25
25
int resultLength = 0 ;
26
- Span < char > result = buffer is null
26
+ Span < char > result = rentedBuffer is null
27
27
? stackalloc char [ JsonConstants . StackallocCharThreshold ]
28
- : buffer ;
28
+ : rentedBuffer ;
29
29
30
30
void ExpandBuffer ( ref Span < char > result )
31
31
{
32
- char [ ] bufferNew = ArrayPool < char > . Shared . Rent ( result . Length * 2 ) ;
32
+ char [ ] newBuffer = ArrayPool < char > . Shared . Rent ( result . Length * 2 ) ;
33
33
34
- result . CopyTo ( bufferNew ) ;
34
+ result . CopyTo ( newBuffer ) ;
35
35
36
- if ( buffer is not null )
36
+ if ( rentedBuffer is not null )
37
37
{
38
- ArrayPool < char > . Shared . Return ( buffer , clearArray : true ) ;
38
+ result . Slice ( 0 , resultLength ) . Clear ( ) ;
39
+ ArrayPool < char > . Shared . Return ( rentedBuffer ) ;
39
40
}
40
41
41
- buffer = bufferNew ;
42
- result = buffer ;
42
+ rentedBuffer = newBuffer ;
43
+ result = rentedBuffer ;
43
44
}
44
45
45
46
void WriteWord ( ReadOnlySpan < char > word , ref Span < char > result )
@@ -139,9 +140,10 @@ void WriteWord(ReadOnlySpan<char> word, ref Span<char> result)
139
140
140
141
name = result . Slice ( 0 , resultLength ) . ToString ( ) ;
141
142
142
- if ( buffer is not null )
143
+ if ( rentedBuffer is not null )
143
144
{
144
- ArrayPool < char > . Shared . Return ( buffer , clearArray : true ) ;
145
+ result . Slice ( 0 , resultLength ) . Clear ( ) ;
146
+ ArrayPool < char > . Shared . Return ( rentedBuffer ) ;
145
147
}
146
148
147
149
return name ;
0 commit comments