Skip to content

Commit c57303f

Browse files
committed
Simplify NumericConversion for signed integers
1 parent bd83421 commit c57303f

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

AssetRipper.TextureDecoder.ColorGenerator/NumericConversionGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ private static void WriteConvertMethod(IndentedTextWriter writer, CSharpPrimitiv
121121
}
122122
else if (from.IsSignedInteger(out CSharpPrimitives.Data? unsignedFrom))
123123
{
124-
writer.WriteLine($"{unsignedFrom.LangName} unsigned = {ChangeSign}(value);");
125-
writer.WriteLine($"return {ConvertMethodName(unsignedFrom.Type)}<TTo>(unsigned);");
124+
writer.WriteLine($"return {ConvertMethodName(unsignedFrom.Type)}<TTo>({ChangeSign}(value));");
126125
}
127126
else
128127
{

AssetRipper.TextureDecoder/Rgb/NumericConversion.g.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ public static TTo Convert<TFrom, TTo>(TFrom value) where TFrom : unmanaged where
8888
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
8989
private static TTo ConvertSByte<TTo>(sbyte value) where TTo : unmanaged
9090
{
91-
byte unsigned = ChangeSign(value);
92-
return ConvertByte<TTo>(unsigned);
91+
return ConvertByte<TTo>(ChangeSign(value));
9392
}
9493

9594
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
@@ -230,8 +229,7 @@ private static TTo ConvertByte<TTo>(byte value) where TTo : unmanaged
230229
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
231230
private static TTo ConvertInt16<TTo>(short value) where TTo : unmanaged
232231
{
233-
ushort unsigned = ChangeSign(value);
234-
return ConvertUInt16<TTo>(unsigned);
232+
return ConvertUInt16<TTo>(ChangeSign(value));
235233
}
236234

237235
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
@@ -371,8 +369,7 @@ private static TTo ConvertUInt16<TTo>(ushort value) where TTo : unmanaged
371369
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
372370
private static TTo ConvertInt32<TTo>(int value) where TTo : unmanaged
373371
{
374-
uint unsigned = ChangeSign(value);
375-
return ConvertUInt32<TTo>(unsigned);
372+
return ConvertUInt32<TTo>(ChangeSign(value));
376373
}
377374

378375
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
@@ -541,8 +538,7 @@ private static TTo ConvertUIntPtr<TTo>(nuint value) where TTo : unmanaged
541538
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
542539
private static TTo ConvertInt64<TTo>(long value) where TTo : unmanaged
543540
{
544-
ulong unsigned = ChangeSign(value);
545-
return ConvertUInt64<TTo>(unsigned);
541+
return ConvertUInt64<TTo>(ChangeSign(value));
546542
}
547543

548544
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
@@ -686,8 +682,7 @@ private static TTo ConvertUInt64<TTo>(ulong value) where TTo : unmanaged
686682
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
687683
private static TTo ConvertInt128<TTo>(Int128 value) where TTo : unmanaged
688684
{
689-
UInt128 unsigned = ChangeSign(value);
690-
return ConvertUInt128<TTo>(unsigned);
685+
return ConvertUInt128<TTo>(ChangeSign(value));
691686
}
692687

693688
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]

0 commit comments

Comments
 (0)