-
Notifications
You must be signed in to change notification settings - Fork 179
Open
Description
I wanted to benchmark the library and ran into an issue for the StringBuilder.Insert equivalent method. Here is a simple program that replicated the issue:
using System;
using Cysharp.Text;
public static class Program
{
private static int Main(string[] args)
{
string result = ZStringBuilderInsert();
return 0;
}
private static string ZStringBuilderInsert()
{
var stringArray = new string[100];
for (int i = 0; i < stringArray.Length; i++)
{
stringArray[i] = new string('A', 1000);
}
using (Utf16ValueStringBuilder sb = ZString.CreateStringBuilder())
{
for (var i = stringArray.Length - 1; i >= 0; i--)
{
var part = stringArray[i];
try
{
sb.Insert(0, part);
}
catch (Exception e)
{
Console.WriteLine($"Error during string concatenation #{i}: " + e.Message);
throw;
}
}
return sb.ToString();
}
}
}This results in the following error:
MicroBenchmarks/bin/Release/net8.0/MicroBenchmarks
Error during string concatenation #67: Destination is too short. (Parameter 'destination')
Unhandled exception. System.ArgumentException: Destination is too short. (Parameter 'destination')
at Cysharp.Text.Utf16ValueStringBuilder.Insert(Int32 index, ReadOnlySpan`1 value, Int32 count)
at Cysharp.Text.Utf16ValueStringBuilder.Insert(Int32 index, String value)
at MicroBenchmarks.Program.ZStringBuilderInsert() in /Users/johannes.deml/Documents/CSharp/MicroBenchmarksDotNet/MicroBenchmarks/Program.cs:line 39
at MicroBenchmarks.Program.Main(String[] args) in /Users/johannes.deml/Documents/CSharp/MicroBenchmarksDotNet/MicroBenchmarks/Program.cs:line 20
Process finished with exit code 134.
I guess there is an issue with resizing the buffer? I didn't look too deep into the issue, but I didn't find it tracked here, so I thought it is a good idea to open up an issue for the exception.
Metadata
Metadata
Assignees
Labels
No labels