|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.IO; |
4 | 4 | using System.IO.Pipelines; |
5 | 5 | using System.Linq; |
6 | 6 | using System.Text; |
7 | 7 |
|
8 | | -#if !NETCOREAPP |
9 | | -using System.Buffers; |
10 | | -#endif |
11 | | - |
12 | 8 | namespace BencodeNET |
13 | 9 | { |
14 | 10 | internal static class UtilityExtensions |
@@ -105,46 +101,23 @@ public static bool TrySetLength(this Stream stream, long length) |
105 | 101 |
|
106 | 102 | public static void Write(this Stream stream, int number) |
107 | 103 | { |
108 | | -#if NETCOREAPP |
109 | 104 | Span<byte> buffer = stackalloc byte[11]; |
110 | 105 | var bytesRead = Encoding.ASCII.GetBytes(number.ToString().AsSpan(), buffer); |
111 | 106 | stream.Write(buffer.Slice(0, bytesRead)); |
112 | | -#else |
113 | | - var str = number.ToString(); |
114 | | - var buffer = ArrayPool<byte>.Shared.Rent(str.Length); |
115 | | - var count = Encoding.ASCII.GetBytes(str, 0, str.Length, buffer, 0); |
116 | | - stream.Write(buffer, 0, count); |
117 | | - ArrayPool<byte>.Shared.Return(buffer); |
118 | | -#endif |
119 | 107 | } |
120 | 108 |
|
121 | 109 | public static void Write(this Stream stream, long number) |
122 | 110 | { |
123 | | -#if NETCOREAPP |
124 | 111 | Span<byte> buffer = stackalloc byte[20]; |
125 | 112 | var bytesRead = Encoding.ASCII.GetBytes(number.ToString().AsSpan(), buffer); |
126 | 113 | stream.Write(buffer.Slice(0, bytesRead)); |
127 | | -#else |
128 | | - var str = number.ToString(); |
129 | | - var buffer = ArrayPool<byte>.Shared.Rent(str.Length); |
130 | | - var count = Encoding.ASCII.GetBytes(str, 0, str.Length, buffer, 0); |
131 | | - stream.Write(buffer, 0, count); |
132 | | - ArrayPool<byte>.Shared.Return(buffer); |
133 | | -#endif |
134 | 114 | } |
135 | 115 |
|
136 | 116 | public static void Write(this Stream stream, char c) |
137 | 117 | { |
138 | 118 | stream.WriteByte((byte) c); |
139 | 119 | } |
140 | 120 |
|
141 | | -#if !NETCOREAPP |
142 | | - public static void Write(this Stream stream, byte[] bytes) |
143 | | - { |
144 | | - stream.Write(bytes, 0, bytes.Length); |
145 | | - } |
146 | | -#endif |
147 | | - |
148 | 121 | public static void WriteChar(this PipeWriter writer, char c) |
149 | 122 | { |
150 | 123 | writer.GetSpan(1)[0] = (byte) c; |
|
0 commit comments