Tail call slowpath

This commit is contained in:
Jöran Malek 2023-11-29 23:20:20 +01:00
parent 4c7671b396
commit 27e77ed39a

View file

@ -1,6 +1,7 @@
using System.Buffers;
using System.Globalization;
using DotNext;
using DotNext.Buffers;
namespace pdns_dhcp.Kea;
@ -9,10 +10,14 @@ public static class KeaDhcpLease
{
private static ReadOnlySpan<char> EscapeTag => ['&', '#', 'x'];
// ref: https://github.com/isc-projects/kea/blob/Kea-2.5.3/src/lib/util/csv_file.cc#L479
public static string Unescape(in ReadOnlySpan<char> text)
{
int esc_pos = text.IndexOf(EscapeTag);
return esc_pos == -1 ? text.ToString() : SlowPath(esc_pos, text);
return text.IndexOf(EscapeTag) switch
{
-1 => text.ToString(),
int i => SlowPath(i, text)
};
static string SlowPath(int esc_pos, in ReadOnlySpan<char> text)
{