File tree Expand file tree Collapse file tree
ServiceStack.Text/src/ServiceStack.Text Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public static StringBuilder Allocate()
1818 return new StringBuilder ( ) ;
1919
2020 ret . Length = 0 ;
21- cache = null ; //don't re-issue cached instance until it's freed
21+ cache = null ; //don't re-issue cached instance until it's freed
2222 return ret ;
2323 }
2424
@@ -43,17 +43,22 @@ public static class StringBuilderCacheAlt
4343 [ ThreadStatic ]
4444 static StringBuilder cache ;
4545
46- public static StringBuilder Allocate ( )
46+ public static StringBuilder Allocate ( int capacity )
4747 {
4848 var ret = cache ;
4949 if ( ret == null )
50- return new StringBuilder ( ) ;
50+ return new StringBuilder ( capacity ) ;
5151
5252 ret . Length = 0 ;
53- cache = null ; //don't re-issue cached instance until it's freed
53+ cache = null ; //don't re-issue cached instance until it's freed
5454 return ret ;
5555 }
5656
57+ public static StringBuilder Allocate ( )
58+ {
59+ return Allocate ( 16 ) ; // 16 is the default capacity for StringBuilder
60+ }
61+
5762 public static void Free ( StringBuilder sb )
5863 {
5964 cache = sb ;
@@ -80,7 +85,7 @@ public static StringBuilder Allocate()
8085 return new StringBuilder ( ) ;
8186
8287 ret . Length = 0 ;
83- cache = null ; //don't re-issue cached instance until it's freed
88+ cache = null ; //don't re-issue cached instance until it's freed
8489 return ret ;
8590 }
8691
You can’t perform that action at this time.
0 commit comments