From 27e77ed39aedbc3b5a5401f35490b9f0d80de4d1 Mon Sep 17 00:00:00 2001 From: AliveDevil Date: Wed, 29 Nov 2023 23:20:20 +0100 Subject: [PATCH] Tail call slowpath --- src/pdns-dhcp/Kea/KeaDhcpLease.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pdns-dhcp/Kea/KeaDhcpLease.cs b/src/pdns-dhcp/Kea/KeaDhcpLease.cs index ae24491..47f8ea8 100644 --- a/src/pdns-dhcp/Kea/KeaDhcpLease.cs +++ b/src/pdns-dhcp/Kea/KeaDhcpLease.cs @@ -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 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 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 text) {