Skip to content

Commit 3156cbb

Browse files
committed
Compacted UIntFloat usage
1 parent 9d555bb commit 3156cbb

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitStream.cs

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ public void WriteBit(bool bit)
301301
/// <param name="value">Value to write</param>
302302
public void WriteSingle(float value)
303303
{
304-
UIntFloat conversion = new UIntFloat();
305-
conversion.floatValue = value;
306-
uint binary = conversion.intValue;
307-
WriteUInt32(binary);
304+
WriteUInt32(new UIntFloat
305+
{
306+
floatValue = value
307+
}.intValue);
308308
}
309309

310310
/// <summary>
@@ -313,10 +313,10 @@ public void WriteSingle(float value)
313313
/// <param name="value">Value to write</param>
314314
public void WriteDouble(double value)
315315
{
316-
UIntFloat conversion = new UIntFloat();
317-
conversion.doubleValue = value;
318-
ulong binary = conversion.longValue;
319-
WriteUInt64(binary);
316+
WriteUInt64(new UIntFloat
317+
{
318+
doubleValue = value
319+
}.longValue);
320320

321321
}
322322

@@ -326,10 +326,10 @@ public void WriteDouble(double value)
326326
/// <param name="value">Value to write</param>
327327
public void WriteSinglePacked(float value)
328328
{
329-
UIntFloat conversion = new UIntFloat();
330-
conversion.floatValue = value;
331-
uint binary = conversion.intValue;
332-
WriteUInt32Packed(binary);
329+
WriteUInt32Packed(new UIntFloat
330+
{
331+
floatValue = value
332+
}.intValue);
333333
}
334334

335335
/// <summary>
@@ -338,11 +338,10 @@ public void WriteSinglePacked(float value)
338338
/// <param name="value">Value to write</param>
339339
public void WriteDoublePacked(double value)
340340
{
341-
UIntFloat conversion = new UIntFloat();
342-
conversion.doubleValue = value;
343-
ulong binary = conversion.longValue;
344-
345-
WriteUInt64Packed(binary);
341+
WriteUInt64Packed(new UIntFloat
342+
{
343+
doubleValue = value
344+
}.longValue);
346345
}
347346

348347
/// <summary>
@@ -521,11 +520,10 @@ public void WriteRotation(Quaternion rotation, int bytesPerAngle)
521520
/// <returns>The read value</returns>
522521
public float ReadSingle()
523522
{
524-
uint read = ReadUInt32();
525-
526-
UIntFloat conversion = new UIntFloat();
527-
conversion.intValue = read;
528-
return conversion.floatValue;
523+
return new UIntFloat
524+
{
525+
intValue = ReadUInt32()
526+
}.floatValue;
529527
}
530528

531529

@@ -535,11 +533,10 @@ public float ReadSingle()
535533
/// <returns>The read value</returns>
536534
public double ReadDouble()
537535
{
538-
ulong read = ReadUInt64();
539-
540-
UIntFloat conversion = new UIntFloat();
541-
conversion.longValue = read;
542-
return conversion.doubleValue;
536+
return new UIntFloat
537+
{
538+
longValue = ReadUInt64()
539+
}.doubleValue;
543540
}
544541

545542

@@ -549,10 +546,10 @@ public double ReadDouble()
549546
/// <returns>The read value</returns>
550547
public float ReadSinglePacked()
551548
{
552-
uint read = ReadUInt32Packed();
553-
UIntFloat conversion = new UIntFloat();
554-
conversion.intValue = read;
555-
return conversion.floatValue;
549+
return new UIntFloat
550+
{
551+
intValue = ReadUInt32Packed()
552+
}.floatValue;
556553
}
557554

558555
/// <summary>
@@ -561,10 +558,10 @@ public float ReadSinglePacked()
561558
/// <returns>The read value</returns>
562559
public double ReadDoublePacked()
563560
{
564-
ulong read = ReadUInt64Packed();
565-
UIntFloat conversion = new UIntFloat();
566-
conversion.longValue = read;
567-
return conversion.doubleValue;
561+
return new UIntFloat
562+
{
563+
longValue = ReadUInt64Packed()
564+
}.doubleValue;
568565
}
569566

570567
/// <summary>

0 commit comments

Comments
 (0)