Skip to content
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

Implement IUtf8SpanParsable on IPAddress and IPNetwork #102144

Merged
merged 45 commits into from
Oct 24, 2024

Commits on May 6, 2024

  1. Changed IP address parsers to use generics

    This is preparation for the work required to enable IUtf8SpanParsable support on IPAddress and IPNetwork.
    Also replaced a few instances of unsafe code with spans.
    This uses the same style of generic constraints as the numeric parsing in corelib (although it can't access IUtfChar<TSelf>.)
    All tests pass, although the UTF8 code paths haven't yet been tested.
    Some restructuring is pending as I plumb IPAddressParser to the updated generic methods.
    Future commits will handle the downstream dependencies of IPvXAddressHelper - at present, this looks like Uri and TargetHostNameHelper.
    edwardneal committed May 6, 2024
    Configuration menu
    Copy the full SHA
    81ab847 View commit details
    Browse the repository at this point in the history
  2. Moved generic type definitions to parser classes

    This allows me to eliminate the nested class and now-redundant generic type constraints on each method
    edwardneal committed May 6, 2024
    Configuration menu
    Copy the full SHA
    2bf97eb View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    223cece View commit details
    Browse the repository at this point in the history

Commits on May 7, 2024

  1. System.Private.Uri changes

    These are just the changes required to make System.Private.Uri compile.
    * Split IPAddressParser and IPv6AddressHelper into multiple files and shared common components between projects.
    * Updated some of the Uri-specific additions to IPvXAddressHelper files to use spans.
    * Minor adjustments to project files to support the above.
    edwardneal committed May 7, 2024
    Configuration menu
    Copy the full SHA
    b9e3a62 View commit details
    Browse the repository at this point in the history

Commits on May 13, 2024

  1. Configuration menu
    Copy the full SHA
    4e580ac View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8ff7241 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f627e44 View commit details
    Browse the repository at this point in the history
  4. Brief tidy-up of System.Net.Primitives ref project and csproj

    Removed a using statement in the ref project, small reduction in the csproj diff for System.Net.Primitives
    edwardneal committed May 13, 2024
    Configuration menu
    Copy the full SHA
    1f52945 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    3710a7a View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    1f4968c View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    ed8c666 View commit details
    Browse the repository at this point in the history

Commits on Jun 14, 2024

  1. Configuration menu
    Copy the full SHA
    3c6e190 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    ea95067 View commit details
    Browse the repository at this point in the history

Commits on Jun 19, 2024

  1. Configuration menu
    Copy the full SHA
    d478e82 View commit details
    Browse the repository at this point in the history

Commits on Jun 22, 2024

  1. Removed generic type definition from classes

    Moved the generic type definition from the IP*AddressParser classes to individual methods, and moved the constant-value fields to local variables.
    Swapped out the arrays in these constant-value fields to a ReadOnlySpan to reduce allocations.
    Replaced calls to TChar.CreateTruncating with TChar.CreateChecked.
    edwardneal committed Jun 22, 2024
    Configuration menu
    Copy the full SHA
    c42c706 View commit details
    Browse the repository at this point in the history
  2. Replaced ref parameter with out parameter, propagated

    Also made one adjustment in Uri so that it uses BinaryPrimitives to convert a long to a Span<byte>, rather than manual bit shifts.
    edwardneal committed Jun 22, 2024
    Configuration menu
    Copy the full SHA
    49bc3a5 View commit details
    Browse the repository at this point in the history

Commits on Jun 23, 2024

  1. Configuration menu
    Copy the full SHA
    3378947 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    66ec8c2 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    afdee99 View commit details
    Browse the repository at this point in the history
  4. Code review feedback: initial work

    Renamed bytesConsumed parameter to charsConsumed.
    `IPNetwork.TryParse(ReadOnlySpan<byte>, IPNetwork)` now finds the last index of a '/' rather than the first. This syncs its behaviour with the `ReadOnlySpan<char>` equivalent.
    Removed unnecessary type constraints which lingered after the removal of the class-level generic type constraint.
    edwardneal committed Jun 23, 2024
    Configuration menu
    Copy the full SHA
    043120f View commit details
    Browse the repository at this point in the history
  5. Removed unnecessary lastSequence modification

    This is only used when handling an IPv4 address embedded inside an IPv6 address, but this can only appear once, so the modification is unnecessary
    edwardneal committed Jun 23, 2024
    Configuration menu
    Copy the full SHA
    c593694 View commit details
    Browse the repository at this point in the history

Commits on Jul 2, 2024

  1. Code review changes

    * Completed rename process of bytesConsumed to charsConsumed.
    * Replaced remaining reference of TChar.CreateChecked with CreateTruncating.
    * Removed unnecessary nullability annotation.
    * Formatting change
    edwardneal committed Jul 2, 2024
    Configuration menu
    Copy the full SHA
    4aff60e View commit details
    Browse the repository at this point in the history

Commits on Jul 4, 2024

  1. Optimisations to IPv[4/6]AddressHelper

    * Removed use of helper method for number parsing.
    * Removed redundant check of parts[0] in IPv4AddressHelper.
    * Added basic heuristic to IPv6AddressHelper to avoid searching for an embedded IPv4 address if the string doesn't contain a '.'.
    edwardneal committed Jul 4, 2024
    Configuration menu
    Copy the full SHA
    8c41d9b View commit details
    Browse the repository at this point in the history
  2. Cleaned up IPAddressParser.Common.cs

    IPAddressParser.Common.cs is no longer needed. This should also clean up the PR diff
    edwardneal committed Jul 4, 2024
    Configuration menu
    Copy the full SHA
    64c639c View commit details
    Browse the repository at this point in the history
  3. .sln file cleanup

    edwardneal committed Jul 4, 2024
    Configuration menu
    Copy the full SHA
    f290a3a View commit details
    Browse the repository at this point in the history

Commits on Jul 6, 2024

  1. Testing micro-optimisations in IPv4 address parser

    * Slightly reducing memory usage by storing the parts as uints.
    * Removing unnecessary assignment of the maximum digit value for octal, deferring another.
    * Removed case-insensitivity in the hexadecimal parsing.
    * Remove unnecessary bitmasks in final assembly of address - values have already been verified as < 0xFF.
    edwardneal committed Jul 6, 2024
    Configuration menu
    Copy the full SHA
    65027db View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cd73915 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    385ee62 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    f7d4298 View commit details
    Browse the repository at this point in the history

Commits on Jul 12, 2024

  1. Code review

    * Reverted from Spans to pointers
    edwardneal committed Jul 12, 2024
    Configuration menu
    Copy the full SHA
    cb1d208 View commit details
    Browse the repository at this point in the history
  2. Additional optimisations post-benchmark

    * Hoisted a condition out of its loop.
    * Switched from a series of comparisons when validating a hex digit to a simple table lookup.
    * Adjusted IPv6AddressHelper.Parse to eliminate range checks on the components. Nothing reaches .Parse without being validated, so there's no overflow risk here.
    edwardneal committed Jul 12, 2024
    Configuration menu
    Copy the full SHA
    0f3bbaf View commit details
    Browse the repository at this point in the history

Commits on Jul 17, 2024

  1. Performance improvement

    Mostly in the IPv6 parsing.
    * Removed HexConverter, which adds a little more latency than expected.
    * For short (<= 16) IPv6 addresses, ROS.Contains and ROS.IndexOf are more expensive than iterating over each character.
    edwardneal committed Jul 17, 2024
    Configuration menu
    Copy the full SHA
    1f8a166 View commit details
    Browse the repository at this point in the history
  2. Changes following code review

    Style/comment changes to IPv4AddressHelper.
    Swapped IPv6AddressHelper back to the previous switch block.
    edwardneal committed Jul 17, 2024
    Configuration menu
    Copy the full SHA
    21f1f86 View commit details
    Browse the repository at this point in the history

Commits on Jul 20, 2024

  1. Initial response to newest review

    * Removed references to unchecked.
    * Changed numeric character detection to align with char.IsAsciiDigit.
    * Changed hex character detection to use HexConverter.
    * Cosmetic change: reordered if-condition and changed comment to match - slightly cleans up diff.
    * Cosmetic change: line spacing.
    edwardneal committed Jul 20, 2024
    Configuration menu
    Copy the full SHA
    70a60a5 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e0c49c2 View commit details
    Browse the repository at this point in the history

Commits on Jul 22, 2024

  1. Configuration menu
    Copy the full SHA
    94b2dd1 View commit details
    Browse the repository at this point in the history
  2. PInvoke/PAL cleanup

    There are now no circumstances where a string is passed to if_nametoindex or SystemNative_InterfaceNameToIndex, or the calling InterfaceNameToIndex method in InterfaceInfoPal. Removed these.
    edwardneal committed Jul 22, 2024
    Configuration menu
    Copy the full SHA
    02a7a84 View commit details
    Browse the repository at this point in the history
  3. Added assertion

    An interface name comes from a scope in a valid IPv6 address. There'll always be at least three characters (::%) in front of the scope, so taking the length of an interface name which stripping these three leading characters away and adds a single null terminator will never overflow an integer.
    edwardneal committed Jul 22, 2024
    Configuration menu
    Copy the full SHA
    c352e01 View commit details
    Browse the repository at this point in the history

Commits on Jul 28, 2024

  1. Replaced usage of if_nametoindex

    This eliminates a number of changes required to transcode from UTF8 and Unicode to ANSI.
    Instead of using if_nametoindex on Windows, this now uses ConvertInterfaceNameToLuidW & ConvertInterfaceLuidToIndex.
    edwardneal committed Jul 28, 2024
    Configuration menu
    Copy the full SHA
    2da63cb View commit details
    Browse the repository at this point in the history

Commits on Jul 30, 2024

  1. Moved interface name tests

    When running in a container, Windows does not have a static loopback interface name.
    Moved tests of InterfaceInfoPal to the PalTests project, rather than testing with hardcoded IP addresses with real scope IDs.
    Made the tests use real (and in Windows' case, dynamic) interface names.
    edwardneal committed Jul 30, 2024
    Configuration menu
    Copy the full SHA
    1ba7107 View commit details
    Browse the repository at this point in the history

Commits on Oct 6, 2024

  1. Corrected PInvoke signatures and Unix InterfaceInfoPal

    * SetLastError has the correct value in the Windows interop layer.
    * Preserve InterfaceNameToIndex's errno in the Unix InterfaceInfoPal.
    edwardneal committed Oct 6, 2024
    Configuration menu
    Copy the full SHA
    038d3a6 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b79a6f5 View commit details
    Browse the repository at this point in the history

Commits on Oct 19, 2024

  1. Performance optimisations

    * Replaced int.CreateTruncating with a JIT pattern which converts from TChar to a ushort.
    * Removed various TChar.CreateTruncating constants, reinstating direct character constants.
    * Replaced branch statements when parsing IPv4 numerics with a HexConverter lookup.
    * IPv4 parts stored in an array of longs to improve register usage.
    * Small improvement in reassembly to eliminate extra array access.
    * Reverted changes to Uri parsing layer, removing the translation logic between a Span and a pointer for IPv4 addresses.
    edwardneal committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    827e5f8 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1b5ad81 View commit details
    Browse the repository at this point in the history

Commits on Oct 23, 2024

  1. Following code review

    * Replaced ushorts with integers to remove some zero-extensions.
    * Replaced NativeMemory with an ArrayPool<byte>.
    * Removed unnecessary assignment to ch.
    edwardneal committed Oct 23, 2024
    Configuration menu
    Copy the full SHA
    dfb68d2 View commit details
    Browse the repository at this point in the history