fix(core): Converts book packets (#413)
- [X] Splits out BaseBook - [X] Converts book packets - [X] Makes FixHtml faster
This commit is contained in:
parent
3d7c4583a8
commit
a146955f6c
8 changed files with 427 additions and 228 deletions
|
|
@ -14,6 +14,17 @@ namespace Server.Buffers
|
|||
private char[]? _arrayToReturnToPool;
|
||||
private Span<char> _chars;
|
||||
|
||||
// If this ctor is used, you cannot pass in stackalloc ROS for append/replace.
|
||||
public ValueStringBuilder(ReadOnlySpan<char> initialString) : this(initialString.Length)
|
||||
{
|
||||
Append(initialString);
|
||||
}
|
||||
|
||||
public ValueStringBuilder(ReadOnlySpan<char> initialString, Span<char> initialBuffer) : this(initialBuffer)
|
||||
{
|
||||
Append(initialString);
|
||||
}
|
||||
|
||||
public ValueStringBuilder(Span<char> initialBuffer)
|
||||
{
|
||||
_arrayToReturnToPool = null;
|
||||
|
|
@ -21,6 +32,7 @@ namespace Server.Buffers
|
|||
Length = 0;
|
||||
}
|
||||
|
||||
// If this ctor is used, you cannot pass in stackalloc ROS for append/replace.
|
||||
public ValueStringBuilder(int initialCapacity)
|
||||
{
|
||||
_arrayToReturnToPool = ArrayPool<char>.Shared.Rent(initialCapacity);
|
||||
|
|
@ -297,6 +309,37 @@ namespace Server.Buffers
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReplaceAny(ReadOnlySpan<char> oldChars, ReadOnlySpan<char> newChars, int startIndex, int count)
|
||||
{
|
||||
int currentLength = Length;
|
||||
if ((uint)startIndex > (uint)currentLength)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(startIndex));
|
||||
}
|
||||
|
||||
if (count < 0 || startIndex > currentLength - count)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
}
|
||||
|
||||
var slice = _chars;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var indexOf = slice.IndexOfAny(oldChars);
|
||||
if (indexOf == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var chr = slice[indexOf];
|
||||
|
||||
slice[indexOf] = newChars[oldChars.IndexOf(chr)];
|
||||
slice = slice.Slice(indexOf + 1);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Replace(char oldChar, char newChar, int startIndex, int count)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Text;
|
||||
using System.Xml;
|
||||
using Microsoft.Toolkit.HighPerformance.Extensions;
|
||||
using Server.Buffers;
|
||||
using Server.Network;
|
||||
using Server.Random;
|
||||
|
||||
|
|
@ -560,31 +561,10 @@ namespace Server
|
|||
return "";
|
||||
}
|
||||
|
||||
var hasOpen = str.ContainsOrdinal('<');
|
||||
var hasClose = str.ContainsOrdinal('>');
|
||||
var hasPound = str.ContainsOrdinal('#');
|
||||
|
||||
if (!hasOpen && !hasClose && !hasPound)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder(str);
|
||||
|
||||
if (hasOpen)
|
||||
{
|
||||
sb.Replace('<', '(');
|
||||
}
|
||||
|
||||
if (hasClose)
|
||||
{
|
||||
sb.Replace('>', ')');
|
||||
}
|
||||
|
||||
if (hasPound)
|
||||
{
|
||||
sb.Replace('#', '-');
|
||||
}
|
||||
using var sb = new ValueStringBuilder(str, stackalloc char[Math.Min(40960, str.Length)]);
|
||||
ReadOnlySpan<char> invalid = stackalloc []{ '<', '>', '#' };
|
||||
ReadOnlySpan<char> replacement = stackalloc []{ '(', ')', '-' };
|
||||
sb.ReplaceAny(invalid, replacement, 0, sb.Length);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue