Refactor AcBinaryDeserializer for conciseness

Refactored several methods to use ternary operators and single-line returns for early-exit and exception cases. Improved code readability by condensing multi-line if/else and null checks into concise expressions. No changes to functionality.
This commit is contained in:
Loretta 2026-05-15 10:51:05 +02:00
parent 853aa23e37
commit 638be8c52e
1 changed files with 8 additions and 19 deletions

View File

@ -1129,14 +1129,7 @@ public static partial class AcBinaryDeserializer
// H2Q6: non-ASCII short strings now use StringSmall tier (handled below via TypeReaderTable dispatch).
var reader = TypeReaderTable<TInput>.Readers[typeCode];
if (reader != null)
{
return reader(context, targetType);
}
throw new AcBinaryDeserializationException(
$"Unknown type code: {typeCode}",
context.Position, targetType);
return reader != null ? reader(context, targetType) : throw new AcBinaryDeserializationException($"Unknown type code: {typeCode}", context.Position, targetType);
}
/// <summary>
@ -1151,8 +1144,8 @@ public static partial class AcBinaryDeserializer
where TInput : struct, IBinaryInputBase
{
var length = (int)context.ReadVarUInt();
if (length == 0) return string.Empty;
return context.ReadStringUtf8(length);
return length == 0 ? string.Empty : context.ReadStringUtf8(length);
}
// ReadStringSmall / Medium / Big / PlainStringAscii and ReadAndRegisterInternedStringSmall / Medium
@ -1191,8 +1184,7 @@ public static partial class AcBinaryDeserializer
private static object ConvertToTargetType(int value, Type targetType)
{
var info = GetConversionInfo(targetType);
if (info.IsEnum)
return Enum.ToObject(info.UnderlyingType, value);
if (info.IsEnum) return Enum.ToObject(info.UnderlyingType, value);
return info.TypeCode switch
{
@ -1281,12 +1273,10 @@ public static partial class AcBinaryDeserializer
where TInput : struct, IBinaryInputBase
{
var length = (int)context.ReadVarUInt();
if (length == 0) return [];
return context.ReadBytes(length);
return length == 0 ? [] : context.ReadBytes(length);
}
#endregion
#region Object Reading
@ -1376,9 +1366,8 @@ public static partial class AcBinaryDeserializer
{
var typeName = ReadPlainString(context);
var resolvedType = AcSerializerCommon.ResolveTypeName(typeName)
?? throw new AcBinaryDeserializationException(
$"Cannot resolve type '{typeName}' for ObjectWithTypeName at position {context.Position}.",
context.Position, null);
?? throw new AcBinaryDeserializationException($"Cannot resolve type '{typeName}' for ObjectWithTypeName at position {context.Position}.", context.Position, null);
var wrapper = context.GetWrapper(resolvedType);
context.RegisterPolymorphicWrapper(wrapper);
// Next byte is the actual inner marker (Object/Array/Dict/etc.) — read it via ReadValue