fix: Optimizes TextDefinition to eliminate allocations. Removes TextDefinition ctor. (#1221)
### BREAKING CHANGE ### The constructor for `TextDefinition` has been removed. Instead use `TextDefinition.Of()` or cast the integer/string to TextDefinition.
This commit is contained in:
parent
213b7025af
commit
910e06767b
50 changed files with 790 additions and 722 deletions
|
|
@ -112,17 +112,16 @@ public struct Point2D
|
|||
}
|
||||
|
||||
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider provider)
|
||||
{
|
||||
return destination.TryWrite(provider, $"({m_X}, {m_Y})", out charsWritten);
|
||||
}
|
||||
=> destination.TryWrite(provider, $"({m_X}, {m_Y})", out charsWritten);
|
||||
|
||||
public override string ToString() {
|
||||
// Maximum number of characters that are needed to represent this:
|
||||
// 4 characters for (, )
|
||||
// Up to 11 characters to represent each integer
|
||||
Span<char> span = stackalloc char[4+11*2];
|
||||
this.TryFormat(span, out var charsWritten, null, null);
|
||||
return span.Slice(0, charsWritten).ToString();
|
||||
const int maxLength = 4 + 11 * 2;
|
||||
Span<char> span = stackalloc char[maxLength];
|
||||
TryFormat(span, out var charsWritten, null, null);
|
||||
return span[..charsWritten].ToString();
|
||||
}
|
||||
|
||||
public string ToString(string format, IFormatProvider formatProvider)
|
||||
|
|
@ -131,5 +130,4 @@ public struct Point2D
|
|||
// default ToString implementation.
|
||||
return ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue