Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Revert "Temporarily removing use of ReadOnlySpan indexer. (#25881)"
Browse files Browse the repository at this point in the history
This reverts commit f8057cc.
  • Loading branch information
ahsonkhan committed Dec 15, 2017
1 parent 4c6a847 commit 4110bfa
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 201 deletions.
22 changes: 9 additions & 13 deletions src/Common/src/System/Memory/FixedBufferExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,17 @@ internal unsafe static bool FixedBufferEqualsString(this ReadOnlySpan<char> span
if (value == null || value.Length > span.Length)
return false;

fixed (char* spanPtr = &span.DangerousGetPinnableReference())
int i = 0;
for (; i < value.Length; i++)
{
var readWriteSpan = new Span<char>(spanPtr, span.Length);
int i = 0;
for (; i < value.Length; i++)
{
// Strings with embedded nulls can never match as the fixed buffer always null terminates.
if (value[i] == '\0' || value[i] != readWriteSpan[i])
return false;
}

// If we've maxed out the buffer or reached the
// null terminator, we're equal.
return i == span.Length || readWriteSpan[i] == '\0';
// Strings with embedded nulls can never match as the fixed buffer always null terminates.
if (value[i] == '\0' || value[i] != span[i])
return false;
}

// If we've maxed out the buffer or reached the
// null terminator, we're equal.
return i == span.Length || span[i] == '\0';
}
}
}
12 changes: 4 additions & 8 deletions src/System.IO.FileSystem/src/System/IO/PathHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,17 @@ public static unsafe bool IsDotOrDotDot(ReadOnlySpan<char> fileName)
|| (fileName.Length == 2 && fileName[1] != '.'));
}

public static unsafe ReadOnlySpan<char> GetDirectoryNameNoChecks(ReadOnlySpan<char> path)
public static ReadOnlySpan<char> GetDirectoryNameNoChecks(ReadOnlySpan<char> path)
{
if (path.Length == 0)
return ReadOnlySpan<char>.Empty;

int root = PathInternal.GetRootLength(path);
int i = path.Length;
fixed (char* pathPtr = &path.DangerousGetPinnableReference())
if (i > root)
{
var pathSpan = new Span<char>(pathPtr, path.Length);
if (i > root)
{
while (i > root && !PathInternal.IsDirectorySeparator(pathSpan[--i])) ;
return pathSpan.Slice(0, i);
}
while (i > root && !PathInternal.IsDirectorySeparator(path[--i])) ;
return path.Slice(0, i);
}

return ReadOnlySpan<char>.Empty;
Expand Down
12 changes: 4 additions & 8 deletions src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3212,20 +3212,16 @@ private void SetupEncoding(Encoding encoding)
}
}

private unsafe void EatPreamble()
private void EatPreamble()
{
ReadOnlySpan<byte> preamble = _ps.encoding.Preamble;
int preambleLen = preamble.Length;
int i;
fixed (byte* preamblePtr = &preamble.DangerousGetPinnableReference())
for (i = 0; i < preambleLen && i < _ps.bytesUsed; i++)
{
var preambleSpan = new Span<byte>(preamblePtr, preambleLen);
for (i = 0; i < preambleLen && i < _ps.bytesUsed; i++)
if (_ps.bytes[i] != preamble[i])
{
if (_ps.bytes[i] != preambleSpan[i])
{
break;
}
break;
}
}
if (i == preambleLen)
Expand Down
Loading

0 comments on commit 4110bfa

Please sign in to comment.