Commit 984128f
authored
Reduce allocation in TextWriter.NewLine (#121508)
It's reasonably common for a codebase to pick a specific newline string
and set it regardless of OS, but currently that ends up allocating on
every OS each call to set_NewLine.
Two changes:
1. When setting TextWriter.NewLine to the existing value, make it a nop
to avoid unnecessarily calling ToCharArray.
2. When setting TextWriter.NewLine to "\n" on Windows or to "\r\n" on
Unix, use a cached array.1 parent 8f1dc6d commit 984128f
File tree
1 file changed
+15
-2
lines changed- src/libraries/System.Private.CoreLib/src/System/IO
1 file changed
+15
-2
lines changedLines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
| |||
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
115 | | - | |
116 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
117 | 130 | | |
118 | 131 | | |
119 | 132 | | |
| |||
0 commit comments