Previously these wouldn't have helped but also wouldn't really have hurt. However, now that StringBuilder doesn't call ToString() by default on numeric types, these are resulting in unnecessary string allocations.
* Remove some allocations from SocketAddress.ToString
Avoids a string allocation per byte, plus a few other intermediary strings.
* Disable failing SocketAddress.ToString test on Unix
* Remove StringBuilder in System.IO.Pipes marshaling
To get the impersonated user name, we can just stackalloc space for the Win32 call and then create a string from that, instead of allocating a StringBuilder and its underlying char[], paying the associated StringBuilder marshaling costs, and then creating the string from that.
* Fix existing typo in comment
* Remove boxing and ToString allocations from RangeHeaderValue.ToString
The current code uses ToString(object), boxng the long? and then calling ToString on it. By instead first checking whether the value is null and only calling ToString(long), we avoid both the box and the string allocations, for both From and To, relying on StringBuilder's ability to format a long directly into its buffer.
* Avoid StringBuilder/char[]/string allocation/copy in DumpHeaders
We can just write into the existing StringBuilder rather than creating a new one, appending to that, copying it to a string, and then appending that string to the original.
* Adding support for synchronous Ping
* Address PR feedback
* Address additional feedback
* Missed 2nd commented out visibility modifier
* Fix build for UWP
* Remove use of deprecated property
* Refactor to remove need for unsafe block
* Remove redundant calls to Stopwatch.Stop()
* Revert to using IPAddress.Address rather than IPAddress.GetAddressBytes() for IPv4
This change also adds direct tests to CheckX509Hostname, because we still haven't added a strong X509Extension subclass for Subject Alternative Name, which is where more direct exposure would live.
SocketsHttpHandler wasn't even trying to send Negotiate/NTLM auth tokens to a proxy. This was due
to some invalid logic regarding the "usingProxy" field in HttpConnection. Reworked this logic to
be clearer about the various kinds of proxy scenarios.
I refactored the loopback proxy server and made it much more robust. It can now handle multiple
requests and multiple connections which helps test against the other handlers whose behavior is
different in this area. I plan to do further work in consolidating the LoopbackServer and
LoopbackProxyServer classes in future PRs.
I created a separate HttpClientHandlerTest.Proxy.cs file and moved many existing proxy tests and
added new tests. The current HttpClientHandlerTest.cs file is still over 3000 lines and needs more
refactoring to make it easier to maintain and track test scenario coverage.
Fixes#30330
* Expose and Add tests for StringBuilder overloads of TextWriter
Add tests for implementation in https://github.com/dotnet/coreclr/pull/18281
This supports the issue https://github.com/dotnet/corefx/issues/30048
* Remove empty line
* Added tests for empy and large strings for the Text.Write*(StringBuilder) APIs
* Add AppCompat overrides for UWP.
(lost in merge conflict)
* review feedback
Port https://github.com/dotnet/coreclr/pull/18360 to CoreRT
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
* Cross compile compat pack shims against 2.0 and use the 2.1 inbox ones
* Fix build issues and use shims.proj produced facades as ref assemblies in the package
* Exclude System.ValueTuple only on nca2.0 and break compat pack dependency on shims package
* PR Feedback
* PR Feedback
The language rules around span safety that C# and F# adhere to assume
there is no way to create a `Span<T>` wrapper over a `ref` local /
parameter. This means `ref` inputs into a method are not considered when
calculating the allowed lifetime of a returned `Span<T>`. Hence both
CreateSpan and CreateReadOnlySpan will be assumed to have heap lifetime
even when provided stack based inputs. Example:
``` c#
Span<int> Example() {
int i = 42;
Span<int> span = MemoryMarshal.CreateSpan(ref i, length: 1);
return span; // C# and F# will allow this
}
```
In this case the actual lifetime of `span` is that of `i`. Yet the
compiler doesn't consider the `ref i` input and hence believes this must
be heap based and hence safe to return out of the method.
This is okay as these methods are unsafe. But want to explicitly
document that fact.
More information on the safety rules can be found in the [span safety
proposal](https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/span-safety.md)
Currently, if you pass two or more concatenated GZipStreams we will read into the second one (to fill a buffer) but not do anything with that information. This PR modifies the Inflater code to instead look at the appended data for the Gzip header magic bytes and treats the rest of the data stream as an additional data segment if they are found.
More info:
- There is no limit to the number of concatenated GZipStreams supported.
- If a GZipStream is appended with garbage that happens to have its first two bytes equal to the GZip header bytes, then an exception will result. This is an acceptable risk, as garbage appended to a valid GZipStream isn't really usable right now anyways since we read past the end of the first stream into that data to fill our input buffer.
- Added exhaustive tests to test buffer boundary behavior
- Concatenated streams are supported using Read, ReadAsync, CopyTo, etc.
* untested; zero allocs during Socket.Poll and Socket.Select on Windows (aveat: Socket.Select with > cutoff will still allocate)
* use MemoryMarshal.GetReference - cleanly passes null ref for empty span
* remove all the "unsafe"; pretty sure that the "ref" will count as a "fixed" during the P/Invoke
* avoid allocating in Socket.Send/Socket.Receive when passing multiple segments (synchronous API)
* Revert "avoid allocating in Socket.Send/Socket.Receive when passing multiple segments (synchronous API)"
This reverts commit 343b88602bd7974f64ae8247f5415b6bf590a89b.
* use spans for multi-segment sync send/receive
* remove "unsafe" from select - no longer required
* fix nit whitespace
* address @stephentoub feedback from review:
- prefer Foo* to ref Foo in p/invoke
- avoid repeated .Count access
- use const size stackalloc instead of dynamic
- use ArrayPool instead of allocate
- avoid multiple testing of count when determining stack vs heap
- use smaller stack threshold
* add debug assertions to express intent of file descriptor size vs socket list size
* use slice+span.clear to simplify objectsToPin wipe
* Expose CallerArgumentExpressionAttribute (#21809)
* added basic CallerArgumentExpressionAttribute tests
* added test to show that overload without optional parameter is taken over method with
* added tests to illustrate behavior of CallerArgumentExpressionAttribute (final behavior may differ)
* added type CallerArgumentExpressionAttribute to uapaot ApiCompatBaseline
* Moved CallerArgumentExpressionTests to non-netfx section
* added newlines as per review
UnicodeEncoding was taking fast path only when both source and destination were 8-byte aligned. It was not
the case for Unicode.GetString.
The fix is to just check the source alignment as fast path precondition, and use unaligned write for destination.
Also removed alternative fast path that is not needed anymore, tweaked local variable assignments for better
register allocation, and fixed performance issue introduced by recent big endian portability fix.
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
* Added CallerArgumentExpressionAttribute
* Modified CallerAtgumentExpressionAttribute
Removed ArgumentNull check from constructor and reordered members to
be more consistent with other attribute classes.
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
macOS 10.12+ supports clock_gettime (HAVE_CLOCK_MONOTONIC is defined)
However, mach_absolute_time has better resolution and should be used
as the primary clock source.
* Remove dead code from System.ComponentModel.Annotations
* Move tests to correct directory
* Cleanup string.Format usage in exceptions
* Add parameter names to some exceptions
* Address PR feedback