diff options
author | Stephen Toub <stoub@microsoft.com> | 2017-09-24 16:45:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-24 16:45:07 +0300 |
commit | a7f6f470cb2c4cdaafdc3ad85e2520992a8db265 (patch) | |
tree | 1c4f65cb2a3e0892b141ab6db0abbce3ea202ea5 | |
parent | f25f97d837a33534f5a6e2f7da9c0989210d3f4c (diff) |
Use stackalloc directly into Span (#24212)
* Use stackalloc directly into Span
We have a few places in corefx where we were stackalloc'ing into a temporary pointer and then creating a Span from that. Now that we're using a C# compiler which supports stackalloc'ing directly into span, use that feature instead.
* Address PR feedback
10 files changed, 16 insertions, 38 deletions
diff --git a/Documentation/building/windows-instructions.md b/Documentation/building/windows-instructions.md index a908d5491a..7e77f8fc7f 100644 --- a/Documentation/building/windows-instructions.md +++ b/Documentation/building/windows-instructions.md @@ -102,6 +102,11 @@ Once you've built the source code for netfx from the root (`build.cmd -framework For advanced debugging using WinDBG see [Debugging CoreFX on Windows](https://github.com/dotnet/corefx/blob/master/Documentation/debugging/windows-instructions.md) ### Notes +* At any given time, the corefx repo might be configured to use a more recent compiler than +the one used by the most recent Visual Studio IDE release. This means the corefx codebase might +be using language features that are not understood by the IDE, which might result in errors that +show up as red squiggles while writing code. Such errors should, however, not affect the actual compilation. + * Running tests from using the VS test explorer does not currently work after we switched to running on CoreCLR. [We will be working on enabling full VS test integration](https://github.com/dotnet/corefx/issues/1318) but we don't have an ETA yet. In the meantime, use the steps above to launch/debug the tests using the console runner. * VS 2015 is required to debug tests running on CoreCLR as the CoreCLR @@ -209,9 +209,10 @@ <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> <CopyNuGetImplementations>false</CopyNuGetImplementations> </PropertyGroup> - - <!-- Set up handling of build warnings --> + + <!-- Language configuration --> <PropertyGroup> + <LangVersion>latest</LangVersion> <!-- default to allowing all language features --> <WarningLevel>4</WarningLevel> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> diff --git a/src/Common/src/System/Net/Internals/IPAddressExtensions.cs b/src/Common/src/System/Net/Internals/IPAddressExtensions.cs index e52af95df9..1ad0048d56 100644 --- a/src/Common/src/System/Net/Internals/IPAddressExtensions.cs +++ b/src/Common/src/System/Net/Internals/IPAddressExtensions.cs @@ -18,13 +18,7 @@ namespace System.Net.Sockets #pragma warning restore CS0618 case AddressFamily.InterNetworkV6: - Span<byte> addressBytes; - unsafe - { - // TODO https://github.com/dotnet/roslyn/issues/17287: Clean up once we can stackalloc into a span - byte* mem = stackalloc byte[IPAddressParserStatics.IPv6AddressBytes]; - addressBytes = new Span<byte>(mem, IPAddressParserStatics.IPv6AddressBytes); - } + Span<byte> addressBytes = stackalloc byte[IPAddressParserStatics.IPv6AddressBytes]; original.TryWriteBytes(addressBytes, out int bytesWritten); Debug.Assert(bytesWritten == IPAddressParserStatics.IPv6AddressBytes); return new IPAddress(addressBytes, (uint)original.ScopeId); diff --git a/src/Common/src/System/Net/SocketAddress.cs b/src/Common/src/System/Net/SocketAddress.cs index 84166bd706..1115c84f15 100644 --- a/src/Common/src/System/Net/SocketAddress.cs +++ b/src/Common/src/System/Net/SocketAddress.cs @@ -103,13 +103,7 @@ namespace System.Net.Internals if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6) { - Span<byte> addressBytes; - unsafe - { - // TODO https://github.com/dotnet/roslyn/issues/17287: Clean up once we can stackalloc into a span - byte* mem = stackalloc byte[IPAddressParserStatics.IPv6AddressBytes]; - addressBytes = new Span<byte>(mem, IPAddressParserStatics.IPv6AddressBytes); - } + Span<byte> addressBytes = stackalloc byte[IPAddressParserStatics.IPv6AddressBytes]; ipAddress.TryWriteBytes(addressBytes, out int bytesWritten); Debug.Assert(bytesWritten == IPAddressParserStatics.IPv6AddressBytes); @@ -138,13 +132,7 @@ namespace System.Net.Internals { Debug.Assert(Size >= IPv6AddressSize); - Span<byte> address; - unsafe - { - // TODO https://github.com/dotnet/roslyn/issues/17287: Clean up once we can stackalloc into a span - byte* mem = stackalloc byte[IPAddressParserStatics.IPv6AddressBytes]; - address = new Span<byte>(mem, IPAddressParserStatics.IPv6AddressBytes); - } + Span<byte> address = stackalloc byte[IPAddressParserStatics.IPv6AddressBytes]; uint scope; SocketAddressPal.GetIPv6Address(Buffer, address, out scope); diff --git a/src/System.Memory/ref/System.Memory.csproj b/src/System.Memory/ref/System.Memory.csproj index 6226292ea1..0d0db9a2fd 100644 --- a/src/System.Memory/ref/System.Memory.csproj +++ b/src/System.Memory/ref/System.Memory.csproj @@ -6,7 +6,6 @@ <CLSCompliant>false</CLSCompliant> <ProjectGuid>{E883935B-D8FD-4FC9-A189-9D9E7F7EF550}</ProjectGuid> <IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netcoreapp' Or '$(TargetGroup)' == 'uap'">true</IsPartialFacadeAssembly> - <LangVersion>7.2</LangVersion> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" /> diff --git a/src/System.Memory/src/System.Memory.csproj b/src/System.Memory/src/System.Memory.csproj index 04eaf96d32..d551fd6925 100644 --- a/src/System.Memory/src/System.Memory.csproj +++ b/src/System.Memory/src/System.Memory.csproj @@ -9,7 +9,6 @@ <IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netcoreapp' OR '$(TargetGroup)' == 'uap'">true</IsPartialFacadeAssembly> <DefineConstants Condition="'$(TargetGroup)'=='netcoreapp'">$(DefineConstants);netcoreapp</DefineConstants> <DefineConstants Condition="'$(TargetGroup)'=='netstandard1.1'">$(DefineConstants);netstandard11</DefineConstants> - <LangVersion>7.2</LangVersion> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Debug|AnyCPU'" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Release|AnyCPU'" /> @@ -62,4 +61,4 @@ <ProjectReference Include="..\..\System.Numerics.Vectors\src\System.Numerics.Vectors.csproj" /> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> -</Project>
\ No newline at end of file +</Project> diff --git a/src/System.Net.Http/src/System/Net/Http/Managed/AuthenticationHelper.Digest.cs b/src/System.Net.Http/src/System/Net/Http/Managed/AuthenticationHelper.Digest.cs index d46f230ce0..134719ccf7 100644 --- a/src/System.Net.Http/src/System/Net/Http/Managed/AuthenticationHelper.Digest.cs +++ b/src/System.Net.Http/src/System/Net/Http/Managed/AuthenticationHelper.Digest.cs @@ -218,12 +218,7 @@ namespace System.Net.Http private static string GetRandomAlphaNumericString() { const int Length = 16; - Span<byte> randomNumbers; - unsafe - { - byte* ptr = stackalloc byte[Length * 2]; - randomNumbers = new Span<byte>(ptr, Length * 2); - } + Span<byte> randomNumbers = stackalloc byte[Length * 2]; s_rng.GetBytes(randomNumbers); StringBuilder sb = StringBuilderCache.Acquire(Length); diff --git a/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj b/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj index 0b9984d731..4dcd801d24 100644 --- a/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj +++ b/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj @@ -4,7 +4,6 @@ <PropertyGroup> <ProjectGuid>{13CE5E71-D373-4EA6-B3CB-166FF089A42A}</ProjectGuid> <SkipIncludeNewtonsoftJson>true</SkipIncludeNewtonsoftJson> - <LangVersion>7.2</LangVersion> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Debug|AnyCPU'" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Release|AnyCPU'" /> @@ -40,4 +39,4 @@ <EmbeddedResource Include="BinaryFormatterTests.rd.xml" /> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> -</Project>
\ No newline at end of file +</Project> diff --git a/src/System.Runtime/ref/System.Runtime.csproj b/src/System.Runtime/ref/System.Runtime.csproj index 7b13bb87fe..2947fad3fe 100644 --- a/src/System.Runtime/ref/System.Runtime.csproj +++ b/src/System.Runtime/ref/System.Runtime.csproj @@ -5,7 +5,6 @@ <AllowUnsafeBlocks>true</AllowUnsafeBlocks> <IsCoreAssembly>true</IsCoreAssembly> <ProjectGuid>{ADBCF120-3454-4A3C-9D1D-AC4293E795D6}</ProjectGuid> - <LangVersion>7.2</LangVersion> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" /> @@ -16,4 +15,4 @@ <Compile Include="System.Runtime.Manual.cs" /> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> -</Project>
\ No newline at end of file +</Project> diff --git a/src/System.Runtime/tests/System.Runtime.Tests.csproj b/src/System.Runtime/tests/System.Runtime.Tests.csproj index acf928989f..3e24ee11aa 100644 --- a/src/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/System.Runtime/tests/System.Runtime.Tests.csproj @@ -7,7 +7,6 @@ <NoWarn>1718</NoWarn> <DefineConstants Condition="'$(TargetGroup)'=='netcoreapp'">$(DefineConstants);netcoreapp</DefineConstants> <DefineConstants Condition="'$(TargetGroup)'=='uapaot'">$(DefineConstants);uapaot</DefineConstants> - <LangVersion>7.2</LangVersion> </PropertyGroup> <!-- Default configurations to help VS understand the configurations --> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" /> @@ -264,4 +263,4 @@ <EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" /> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> -</Project>
\ No newline at end of file +</Project> |