Skip to content

Commit 8919120

Browse files
committed
The RESP3 null case can skip the initial TryReadUnsignedLengthHeader detection, so we better check after the call. If we do that check, we might as well delete the previous check.
1 parent 1995b4e commit 8919120

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

libs/common/RespReadUtils.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,14 @@ public static bool TryReadUnsignedLengthHeader(out int length, ref byte* ptr, by
316316
if (ptr + 3 > end)
317317
return false;
318318

319-
var readHead = ptr + 1;
320-
var negative = *readHead == '-';
319+
if (!TryReadSignedLengthHeader(out length, ref ptr, end, expectedSigil))
320+
return false;
321321

322-
if (negative)
322+
if (length < 0)
323323
{
324324
RespParsingException.ThrowInvalidStringLength(length);
325325
}
326326

327-
if (!TryReadSignedLengthHeader(out length, ref ptr, end, expectedSigil))
328-
return false;
329-
330327
return true;
331328
}
332329

@@ -924,7 +921,7 @@ public static bool TryReadStringResponseWithLengthHeader(out string result, ref
924921
/// <exception cref="RespParsingException">Thrown if unexpected token is read.</exception>
925922
/// <exception cref="RespParsingException">Thrown if integer overflow occurs.</exception>
926923
[MethodImpl(MethodImplOptions.AggressiveInlining)]
927-
public static bool TryReadPtrWithSignedLengthHeader(ref byte* stringPtr, ref int length, ref byte* ptr, byte* end)
924+
static bool TryReadPtrWithSignedLengthHeader(ref byte* stringPtr, ref int length, ref byte* ptr, byte* end)
928925
{
929926
// Parse RESP string header
930927
if (!TryReadSignedLengthHeader(out length, ref ptr, end))

0 commit comments

Comments
 (0)