Skip to content

Look for places to collapse AsSpan().Slice(start, length) into .AsSpan(start,length) #25131

Closed
dotnet/corefxlab
#2206

Description

@ghost
No description provided.

Activity

  1. ghost
    self-assigned this
    on Feb 21, 2018
  2. tarekgh commented on Mar 7, 2018

    @tarekgh
    Member

    @atsushikan do we still have work to do here? or this is done?

  3. stephentoub commented on Mar 7, 2018

    @stephentoub
    Member

    A quick search in corefx shows this:

      D:\repos\corefx\src\Common\src\CoreLib\System\String.Manipulation.cs(1139):                    this.AsSpan().Slice(thisIdx, count).CopyTo(dstSpan.Slice(dstIdx));
      D:\repos\corefx\src\Common\src\CoreLib\System\String.Manipulation.cs(1151):            this.AsSpan().Slice(thisIdx).CopyTo(dstSpan.Slice(dstIdx));
      D:\repos\corefx\src\Common\src\CoreLib\System\TimeZoneInfo.Unix.cs(1201):                        if (int.TryParse(dateRule.AsSpan().Slice(1, firstDotIndex - 1), out month) &&
      D:\repos\corefx\src\Common\src\CoreLib\System\TimeZoneInfo.Unix.cs(1202):                            int.TryParse(dateRule.AsSpan().Slice(firstDotIndex + 1, secondDotIndex - firstDotIndex - 1), out week) &&
      D:\repos\corefx\src\Common\src\CoreLib\System\TimeZoneInfo.Unix.cs(1203):                            int.TryParse(dateRule.AsSpan().Slice(secondDotIndex + 1), out int day))
      D:\repos\corefx\src\Common\src\CoreLib\System\Globalization\CompareInfo.cs(509):                string1.AsSpan().Slice(offset1, length1),
      D:\repos\corefx\src\Common\src\CoreLib\System\Globalization\CompareInfo.cs(510):                string2.AsSpan().Slice(offset2, length2),
      D:\repos\corefx\src\Common\src\CoreLib\System\Globalization\CompareInfo.cs(534):            return CompareOrdinalIgnoreCase(strA.AsSpan().Slice(indexA, lengthA), strB.AsSpan().Slice(indexB, lengthB));
      D:\repos\corefx\src\Common\src\CoreLib\System\Globalization\DateTimeParse.cs(5048):                        if (m_info.CompareOptionIgnoreCase(Value.Slice(thisPosition, segmentLength), target.AsSpan().Slice(targetPosition, segmentLength)) != 0)
      D:\repos\corefx\src\Common\src\CoreLib\System\Globalization\DateTimeParse.cs(5074):                    if (m_info.CompareOptionIgnoreCase(Value.Slice(thisPosition, segmentLength), target.AsSpan().Slice(targetPosition, segmentLength)) != 0)
      D:\repos\corefx\src\Common\src\CoreLib\System\Globalization\HijriCalendar.Win32.cs(72):                                int advance = Int32.Parse(str.AsSpan().Slice(HijriAdvanceRegKeyEntry.Length), provider:CultureInfo.InvariantCulture);
      D:\repos\corefx\src\Common\src\CoreLib\System\IO\Path.Windows.cs(86):                combinedPath = Join(GetPathRoot(basePath.AsSpan()), path.AsSpan().Slice(1)); // Cut the separator to ensure we don't end up with two separators when joining with the root.
      D:\repos\corefx\src\Common\src\CoreLib\System\IO\Path.Windows.cs(98):                    combinedPath = Join(basePath, path.AsSpan().Slice(2));
      D:\repos\corefx\src\Common\src\CoreLib\System\IO\Path.Windows.cs(108):                            ? JoinInternal(basePath.AsSpan().Slice(0, 4), path, @"\")
      D:\repos\corefx\src\Common\src\CoreLib\System\IO\Path.Windows.cs(109):                            : JoinInternal(basePath.AsSpan().Slice(0, 4), path.AsSpan().Slice(0, 2), @"\", path.AsSpan().Slice(2));
      D:\repos\corefx\src\Common\src\CoreLib\System\IO\PathHelper.Windows.cs(87):                buffer.Append(content.AsSpan().Slice(PathInternal.UncPrefixLength));
      D:\repos\corefx\src\Common\src\CoreLib\System\IO\PathHelper.Windows.cs(201):                        outputBuilder.Append(inputBuilder.AsSpan().Slice(foundIndex, inputBuilder.Length - foundIndex));
      D:\repos\corefx\src\Common\src\CoreLib\System\IO\PathHelper.Windows.cs(221):            ReadOnlySpan<char> output = builderToUse.AsSpan().Slice(rootDifference);
      D:\repos\corefx\src\Common\src\CoreLib\System\Text\StringBuilder.cs(1555):                            itemFormatSpan = format.AsSpan().Slice(startPos, pos - startPos);
      D:\repos\corefx\src\Common\src\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs(26):                    if (!Version.TryParse(OpenSslVersionDescription().AsSpan().Slice(OpenSSL.Length, 5).ToString(), out s_opensslVersion))
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\Asn1V2.Serializer.cs(638):                        valAsMemory.Span.CopyTo(tooBig.AsSpan().Slice(1));
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\Asn1V2.Serializer.cs(884):                                return new ReadOnlyMemory<byte>(rented.AsSpan().Slice(0, bytesWritten).ToArray());
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\Asn1V2.Serializer.cs(915):                                return new ReadOnlyMemory<byte>(rented.AsSpan().Slice(0, bytesWritten).ToArray());
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(102):            if (!tag.TryWrite(_buffer.AsSpan().Slice(_offset, spaceRequired), out int written) ||
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(193):            preEncodedValue.Span.CopyTo(_buffer.AsSpan().Slice(_offset));
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(452):            bitString.CopyTo(_buffer.AsSpan().Slice(_offset));
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(511):                dest = _buffer.AsSpan().Slice(_offset);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(524):            dest = _buffer.AsSpan().Slice(_offset);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(658):            octetString.CopyTo(_buffer.AsSpan().Slice(_offset));
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(710):                dest = _buffer.AsSpan().Slice(_offset);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(719):            dest = _buffer.AsSpan().Slice(_offset);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(846):                int localLen = EncodeSubIdentifier(tmp.AsSpan().Slice(tmpOffset), ref subIdentifier);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(852):                    localLen = EncodeSubIdentifier(tmp.AsSpan().Slice(tmpOffset), ref subIdentifier);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(1124):            Span<byte> baseSpan = _buffer.AsSpan().Slice(_offset);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(1237):            Span<byte> baseSpan = _buffer.AsSpan().Slice(_offset);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(1290):            _buffer.AsSpan().Slice(0, _offset).CopyTo(dest);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(1308):            return _buffer.AsSpan().Slice(0, _offset).ToArray();
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(1475):                    Span<byte> dest = _buffer.AsSpan().Slice(_offset, size);
      D:\repos\corefx\src\Common\src\System\Security\Cryptography\AsnWriter.cs(1520):            WriteConstructedCerOctetString(tag, tmp.AsSpan().Slice(0, size));
      D:\repos\corefx\src\System.Diagnostics.Process\src\System\Diagnostics\Process.Linux.cs(91):                    Double.TryParse(text.AsSpan().Slice(0, length), NumberStyles.AllowDecimalPoint, NumberFormatInfo.InvariantInfo, out uptimeSeconds);
      D:\repos\corefx\src\System.Private.Xml\src\System\Xml\NameTable.cs(243):            ReadOnlySpan<byte> bytes = key.AsSpan().Slice(start, len).AsBytes();
      D:\repos\corefx\src\System.Runtime.Extensions\src\System\IO\StringReader.cs(141):                _s.AsSpan().Slice(_pos, n).CopyTo(buffer);
    
  4. tarekgh commented on Mar 7, 2018

    @tarekgh
    Member

    Work hasn't started on this. (BTW, this work is cleanup and microoptimization rather than "Enhancement.")

    that is what meant by "Enhancement".

    @stephentoub you marked it as up-for-grabs so we should un-assign @atsushikan if you think someone else will pick it up.

  5. stephentoub commented on Mar 7, 2018

    @stephentoub
    Member

    so we should un-assign

    Not necessary unless he wants that. This is just the kind of thing that anyone can do; doesn't require Ati's skill set.

  6. tarekgh commented on Mar 7, 2018

    @tarekgh
    Member

    what I meant, people usually don't pick the assigned issues. anyway, I'll see if I can do this one myself.

  7. khellang commented on Mar 8, 2018

    @khellang
    Member

    What about shipping an analyzer and code fix for this?

  8. assigned and unassigned on Mar 8, 2018
  9. ahsonkhan commented on Apr 12, 2018

    @ahsonkhan
    Contributor
  10. ahsonkhan commented on Apr 13, 2018

    @ahsonkhan
    Contributor

    What about shipping an analyzer and code fix for this?

    See dotnet/corefxlab#2206 (experimental, trying it out)

  11. transferred this issue fromdotnet/corefxon Jan 31, 2020
  12. added this to the 2.1.0 milestone on Jan 31, 2020
  13. ghost locked as resolved and limited conversation to collaborators on Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-MetaenhancementProduct code improvement that does NOT require public API changes/additions

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions