Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Assets/RTLTMPro/Scripts/Runtime/FastStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void Substring(FastStringBuilder output, int start, int length) {
}

public override string ToString() {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(length * 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should set the capacity to the eventual length of the string which we could compute by replicating the surrogate pair logic in our code. 2*length is an upper bound and allocates twice as much memory as is needed in most cases.

for (int i = 0; i < length; i++) {
sb.Append(char.ConvertFromUtf32(array[i]));
}
Expand All @@ -170,10 +170,10 @@ public override string ToString() {

public string ToDebugString()
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(length * 3);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not worry about performance of debug code.

for (int i = 0; i < length; i++)
{
sb.Append("\\");
sb.Append('\\');
sb.Append(array[i].ToString("X"));
}
return sb.ToString();
Expand Down