-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Remove more fixed buffers and replace them with InlineArray #125574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1f28cdd
d61794b
72db930
b0ce107
e43d5c6
e993e13
036c501
c737a54
76e36a4
82cbf69
76c641d
ac6c192
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
|
|
@@ -30,37 +32,56 @@ internal bool Equals(in SYSTEMTIME other) => | |
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
| internal unsafe struct TIME_DYNAMIC_ZONE_INFORMATION | ||
| internal struct TIME_DYNAMIC_ZONE_INFORMATION | ||
| { | ||
| [InlineArray(32)] | ||
| internal struct NameBuffer | ||
| { | ||
| private char _element0; | ||
| } | ||
|
|
||
| [InlineArray(128)] | ||
| internal struct TimeZoneKeyNameBuffer | ||
| { | ||
| private char _element0; | ||
| } | ||
|
|
||
| internal int Bias; | ||
| internal fixed char StandardName[32]; | ||
| internal NameBuffer StandardName; | ||
| internal SYSTEMTIME StandardDate; | ||
| internal int StandardBias; | ||
| internal fixed char DaylightName[32]; | ||
| internal NameBuffer DaylightName; | ||
| internal SYSTEMTIME DaylightDate; | ||
| internal int DaylightBias; | ||
| internal fixed char TimeZoneKeyName[128]; | ||
| internal TimeZoneKeyNameBuffer TimeZoneKeyName; | ||
| internal byte DynamicDaylightTimeDisabled; | ||
|
|
||
| internal string GetTimeZoneKeyName() | ||
| { | ||
| fixed (char* p = TimeZoneKeyName) | ||
| return new string(p); | ||
| ReadOnlySpan<char> span = TimeZoneKeyName; | ||
| int idx = span.IndexOf('\0'); | ||
| return new string(idx >= 0 ? span[..idx] : span); | ||
| } | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
| internal unsafe struct TIME_ZONE_INFORMATION | ||
| internal struct TIME_ZONE_INFORMATION | ||
| { | ||
| [InlineArray(32)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few of these powers of 2 are also relatively common, from what I've seen. Might also be worth a centralized define for them like the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I'll ask github CCA to see what it can unite/deduplicate |
||
| internal struct NameBuffer | ||
| { | ||
| private char _element0; | ||
| } | ||
|
|
||
| internal int Bias; | ||
| internal fixed char StandardName[32]; | ||
| internal NameBuffer StandardName; | ||
| internal SYSTEMTIME StandardDate; | ||
| internal int StandardBias; | ||
| internal fixed char DaylightName[32]; | ||
| internal NameBuffer DaylightName; | ||
| internal SYSTEMTIME DaylightDate; | ||
| internal int DaylightBias; | ||
|
|
||
| internal TIME_ZONE_INFORMATION(in TIME_DYNAMIC_ZONE_INFORMATION dtzi) | ||
| internal unsafe TIME_ZONE_INFORMATION(in TIME_DYNAMIC_ZONE_INFORMATION dtzi) | ||
| { | ||
| // The start of TIME_DYNAMIC_ZONE_INFORMATION has identical layout as TIME_ZONE_INFORMATION | ||
| fixed (TIME_ZONE_INFORMATION* pTo = &this) | ||
|
|
@@ -70,14 +91,16 @@ internal TIME_ZONE_INFORMATION(in TIME_DYNAMIC_ZONE_INFORMATION dtzi) | |
|
|
||
| internal string GetStandardName() | ||
| { | ||
| fixed (char* p = StandardName) | ||
| return new string(p); | ||
| ReadOnlySpan<char> span = StandardName; | ||
| int idx = span.IndexOf('\0'); | ||
| return new string(idx >= 0 ? span[..idx] : span); | ||
| } | ||
|
|
||
| internal string GetDaylightName() | ||
| { | ||
| fixed (char* p = DaylightName) | ||
| return new string(p); | ||
| ReadOnlySpan<char> span = DaylightName; | ||
| int idx = span.IndexOf('\0'); | ||
| return new string(idx >= 0 ? span[..idx] : span); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,43 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
EgorBo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class NtDll | ||
| { | ||
| [LibraryImport(Libraries.NtDll)] | ||
| private static partial int RtlGetVersion(ref RTL_OSVERSIONINFOEX lpVersionInformation); | ||
| private static unsafe partial int RtlGetVersion(RTL_OSVERSIONINFOEX* lpVersionInformation); | ||
|
|
||
| internal static unsafe int RtlGetVersionEx(out RTL_OSVERSIONINFOEX osvi) | ||
| { | ||
| osvi = default; | ||
| osvi.dwOSVersionInfoSize = (uint)sizeof(RTL_OSVERSIONINFOEX); | ||
| return RtlGetVersion(ref osvi); | ||
| fixed (RTL_OSVERSIONINFOEX* p = &osvi) | ||
| return RtlGetVersion(p); | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
| internal unsafe struct RTL_OSVERSIONINFOEX | ||
| internal struct RTL_OSVERSIONINFOEX | ||
| { | ||
| internal uint dwOSVersionInfoSize; | ||
| internal uint dwMajorVersion; | ||
| internal uint dwMinorVersion; | ||
| internal uint dwBuildNumber; | ||
| internal uint dwPlatformId; | ||
| internal fixed char szCSDVersion[128]; | ||
| #if NET | ||
| internal CSDVersionBuffer szCSDVersion; | ||
|
|
||
| [InlineArray(128)] | ||
| internal struct CSDVersionBuffer | ||
| { | ||
| private char _element0; | ||
| } | ||
| #else | ||
| internal unsafe fixed char szCSDVersion[128]; | ||
| #endif | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.