diff --git a/src/Peachpie.Runtime/PhpString.cs b/src/Peachpie.Runtime/PhpString.cs index 28f45bea40..f523a2ce6f 100644 --- a/src/Peachpie.Runtime/PhpString.cs +++ b/src/Peachpie.Runtime/PhpString.cs @@ -1090,7 +1090,7 @@ public string ToString(Encoding encoding) if (chunks != null) { return (chunks is object[] objs) - ? ChunkToString(encoding, objs, _chunksCount) + ? ChunkToString(encoding, objs.AsSpan(0, _chunksCount)) : ChunkToString(encoding, chunks); } else @@ -1099,19 +1099,23 @@ public string ToString(Encoding encoding) } } - static string ChunkToString(Encoding encoding, object[] chunks, int count) + static string ChunkToString(Encoding encoding, ReadOnlySpan chunks) { - if (count == 1) + if (chunks.Length == 1) { return ChunkToString(encoding, chunks[0]); } + else if (chunks.Length == 2) + { + return ChunkToString(encoding, chunks[0]) + ChunkToString(encoding, chunks[1]); + } else { var builder = ObjectPools.GetStringBuilder(); - for (int i = 0; i < count; i++) + foreach (var chunk in chunks) { - builder.Append(ChunkToString(encoding, chunks[i])); + builder.Append(ChunkToString(encoding, chunk)); } return ObjectPools.GetStringAndReturn(builder);