Skip to content

Commit 5a36028

Browse files
committed
Performance: Removed LINQ from the Utf8Substring helper.
1 parent 56e4afb commit 5a36028

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

PhpSerializerNET/Extensions/ArrayExtensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ This Source Code Form is subject to the terms of the Mozilla Public
1111
namespace PhpSerializerNET {
1212
internal static class ArrayExtensions {
1313
public static string Utf8Substring(this byte[] array, int start, int length, Encoding encoding) {
14+
byte[] substring = new byte[length];
15+
for(int i = start, j = 0; j < length && i < array.Length; i++, j++){
16+
substring[j] = array[i];
17+
}
1418
if (encoding == Encoding.UTF8) {
15-
return Encoding.UTF8.GetString(array.Skip(start).Take(length).ToArray());
19+
return Encoding.UTF8.GetString(substring);
1620
} else {
1721
return Encoding.UTF8.GetString(
18-
Encoding.Convert(encoding, Encoding.UTF8, array.Skip(start).Take(length).ToArray())
22+
Encoding.Convert(encoding, Encoding.UTF8, substring)
1923
);
2024
}
2125
}

0 commit comments

Comments
 (0)