|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +using System.Buffers.Binary; |
4 | 5 | using System.Collections.Generic;
|
5 | 6 | using System.Diagnostics;
|
6 | 7 | using System.Globalization;
|
@@ -4449,35 +4450,9 @@ private ulong GetUInt64(int pos)
|
4449 | 4450 | return (ulong)((ulong)hi) << 32 | lo;
|
4450 | 4451 | }
|
4451 | 4452 |
|
4452 |
| - private float GetSingle(int offset) |
4453 |
| - { |
4454 |
| - byte[] data = _data; |
4455 |
| - uint tmp = (uint)(data[offset] |
4456 |
| - | data[offset + 1] << 8 |
4457 |
| - | data[offset + 2] << 16 |
4458 |
| - | data[offset + 3] << 24); |
4459 |
| - unsafe |
4460 |
| - { |
4461 |
| - return *((float*)&tmp); |
4462 |
| - } |
4463 |
| - } |
| 4453 | + private float GetSingle(int offset) => BinaryPrimitives.ReadSingleLittleEndian(_data.AsSpan(offset)); |
4464 | 4454 |
|
4465 |
| - private double GetDouble(int offset) |
4466 |
| - { |
4467 |
| - uint lo = (uint)(_data[offset + 0] |
4468 |
| - | _data[offset + 1] << 8 |
4469 |
| - | _data[offset + 2] << 16 |
4470 |
| - | _data[offset + 3] << 24); |
4471 |
| - uint hi = (uint)(_data[offset + 4] |
4472 |
| - | _data[offset + 5] << 8 |
4473 |
| - | _data[offset + 6] << 16 |
4474 |
| - | _data[offset + 7] << 24); |
4475 |
| - ulong tmp = ((ulong)hi) << 32 | lo; |
4476 |
| - unsafe |
4477 |
| - { |
4478 |
| - return *((double*)&tmp); |
4479 |
| - } |
4480 |
| - } |
| 4455 | + private double GetDouble(int offset) => BinaryPrimitives.ReadDoubleLittleEndian(_data.AsSpan(offset)); |
4481 | 4456 |
|
4482 | 4457 | private Exception ThrowUnexpectedToken(BinXmlToken token)
|
4483 | 4458 | {
|
|
0 commit comments