diff options
| author | Mary <mary@mary.zone> | 2022-06-24 19:04:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-24 19:04:57 +0200 |
| commit | 30ee70a9bc9529772198a51b1b9a605932d2ea96 (patch) | |
| tree | 93073c3338d139189685fc292c5fd1ad147a2c86 /Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs | |
| parent | 232b1012b0c981830ac46bd5024dcc0e35075301 (diff) | |
time: Make TimeZoneRule blittable and avoid copies (#3361)
* time: Make TimeZoneRule blittable and avoid copies
This drastically reduce overhead of using TimeZoneRule around the
codebase.
Effect on games is unknown
* Add missing Box type
* Ensure we clean the structure still
This doesn't perform any copies
* Address gdkchan's comments
* Simplify Box
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs')
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs b/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs index 202099b0..24032999 100644 --- a/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs +++ b/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs @@ -4,9 +4,12 @@ using Ryujinx.Cpu; using Ryujinx.HLE.HOS.Services.Time.Clock; using Ryujinx.HLE.HOS.Services.Time.TimeZone; using Ryujinx.HLE.Utilities; +using Ryujinx.Memory; using System; using System.Diagnostics; using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Services.Time.StaticService { @@ -165,11 +168,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService using (MemoryStream timeZoneBinaryStream = new MemoryStream(temp)) { - result = _timeZoneManager.ParseTimeZoneRuleBinary(out TimeZoneRule timeZoneRule, timeZoneBinaryStream); - - if (result == ResultCode.Success) + using (WritableRegion region = context.Memory.GetWritableRegion(timeZoneRuleBufferPosition, Unsafe.SizeOf<TimeZoneRule>())) { - MemoryHelper.Write(context.Memory, timeZoneRuleBufferPosition, timeZoneRule); + ref TimeZoneRule rule = ref MemoryMarshal.Cast<byte, TimeZoneRule>(region.Memory.Span)[0]; + + result = _timeZoneManager.ParseTimeZoneRuleBinary(ref rule, timeZoneBinaryStream); } } @@ -199,9 +202,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService throw new InvalidOperationException(); } - TimeZoneRule rules = MemoryHelper.Read<TimeZoneRule>(context.Memory, bufferPosition); + ReadOnlySpan<TimeZoneRule> rules = MemoryMarshal.Cast<byte, TimeZoneRule>(context.Memory.GetSpan(bufferPosition, (int)bufferSize)); - ResultCode resultCode = _timeZoneManager.ToCalendarTime(rules, posixTime, out CalendarInfo calendar); + ResultCode resultCode = _timeZoneManager.ToCalendarTime(in rules[0], posixTime, out CalendarInfo calendar); if (resultCode == 0) { @@ -244,9 +247,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService throw new InvalidOperationException(); } - TimeZoneRule rules = MemoryHelper.Read<TimeZoneRule>(context.Memory, inBufferPosition); + ReadOnlySpan<TimeZoneRule> rules = MemoryMarshal.Cast<byte, TimeZoneRule>(context.Memory.GetSpan(inBufferPosition, (int)inBufferSize)); - ResultCode resultCode = _timeZoneManager.ToPosixTime(rules, calendarTime, out long posixTime); + ResultCode resultCode = _timeZoneManager.ToPosixTime(in rules[0], calendarTime, out long posixTime); if (resultCode == ResultCode.Success) { |
