diff options
Diffstat (limited to 'src/Ryujinx.HLE/Utilities/StringUtils.cs')
-rw-r--r-- | src/Ryujinx.HLE/Utilities/StringUtils.cs | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/src/Ryujinx.HLE/Utilities/StringUtils.cs b/src/Ryujinx.HLE/Utilities/StringUtils.cs index 1810b1ad..9b3479ee 100644 --- a/src/Ryujinx.HLE/Utilities/StringUtils.cs +++ b/src/Ryujinx.HLE/Utilities/StringUtils.cs @@ -77,30 +77,28 @@ namespace Ryujinx.HLE.Utilities public static string ReadUtf8String(ServiceCtx context, int index = 0) { ulong position = context.Request.PtrBuff[index].Position; - ulong size = context.Request.PtrBuff[index].Size; + ulong size = context.Request.PtrBuff[index].Size; - using (RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream()) + using RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream(); + while (size-- > 0) { - while (size-- > 0) - { - byte value = context.Memory.Read<byte>(position++); - - if (value == 0) - { - break; - } + byte value = context.Memory.Read<byte>(position++); - ms.WriteByte(value); + if (value == 0) + { + break; } - return Encoding.UTF8.GetString(ms.GetReadOnlySequence()); + ms.WriteByte(value); } + + return Encoding.UTF8.GetString(ms.GetReadOnlySequence()); } public static U8Span ReadUtf8Span(ServiceCtx context, int index = 0) { ulong position = context.Request.PtrBuff[index].Position; - ulong size = context.Request.PtrBuff[index].Size; + ulong size = context.Request.PtrBuff[index].Size; ReadOnlySpan<byte> buffer = context.Memory.GetSpan(position, (int)size); @@ -110,24 +108,23 @@ namespace Ryujinx.HLE.Utilities public static string ReadUtf8StringSend(ServiceCtx context, int index = 0) { ulong position = context.Request.SendBuff[index].Position; - ulong size = context.Request.SendBuff[index].Size; + ulong size = context.Request.SendBuff[index].Size; - using (RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream()) - { - while (size-- > 0) - { - byte value = context.Memory.Read<byte>(position++); + using RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream(); - if (value == 0) - { - break; - } + while (size-- > 0) + { + byte value = context.Memory.Read<byte>(position++); - ms.WriteByte(value); + if (value == 0) + { + break; } - return Encoding.UTF8.GetString(ms.GetReadOnlySequence()); + ms.WriteByte(value); } + + return Encoding.UTF8.GetString(ms.GetReadOnlySequence()); } public static int CompareCStr(ReadOnlySpan<byte> s1, ReadOnlySpan<byte> s2) @@ -156,4 +153,4 @@ namespace Ryujinx.HLE.Utilities return i; } } -}
\ No newline at end of file +} |