Skip to content

Commit

Permalink
Call simpler overloads of Substring and Slice (#68937)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabYourPitchforks authored May 11, 2022
1 parent 72f9cb2 commit 52fd1a5
Show file tree
Hide file tree
Showing 25 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ static void GetMatchingTypes(ModuleDesc module, TypeDesc declaringType, string n
if (indexOfLastDot > 0 && indexOfLastDot < name.Length - 1)
{
namespacepart = name.Substring(indexOfLastDot - 1);
namepart = name.Substring(indexOfLastDot + 1, name.Length - indexOfLastDot - 1);
namepart = name.Substring(indexOfLastDot + 1);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private int Run(string[] args)
Dictionary<string, bool> instructionSetSpecification = new Dictionary<string, bool>();
foreach (string instructionSetSpecifier in instructionSetParams)
{
string instructionSet = instructionSetSpecifier.Substring(1, instructionSetSpecifier.Length - 1);
string instructionSet = instructionSetSpecifier.Substring(1);

bool enabled = instructionSetSpecifier[0] == '+' ? true : false;
if (enabled)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private InstructionSetSupport ConfigureInstructionSetSupport()
Dictionary<string, bool> instructionSetSpecification = new Dictionary<string, bool>();
foreach (string instructionSetSpecifier in instructionSetParams)
{
string instructionSet = instructionSetSpecifier.Substring(1, instructionSetSpecifier.Length - 1);
string instructionSet = instructionSetSpecifier.Substring(1);

bool enabled = instructionSetSpecifier[0] == '+' ? true : false;
if (enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subK
{
subKeyName = (i == -1 || i == keyName.Length) ?
string.Empty :
keyName.Substring(i + 1, keyName.Length - i - 1);
keyName.Substring(i + 1);

return baseKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6508,7 +6508,7 @@ internal void ReadXmlSchema(XmlReader? reader, bool denyResolving)
{
CurrentTableNamespace = CurrentTableFullName.Substring(0, nsSeperator);
}
string CurrentTableName = CurrentTableFullName.Substring(nsSeperator + 1, CurrentTableFullName.Length - nsSeperator - 1);
string CurrentTableName = CurrentTableFullName.Substring(nsSeperator + 1);

currentTable = ds.Tables[CurrentTableName, CurrentTableNamespace];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,13 +755,13 @@ internal static void AddNewActivitySourceTransform(string filterAndPayloadSpec,
{
activitySourceName = entry.Slice(0, eventNameIndex).Trim();

ReadOnlySpan<char> suffixPart = entry.Slice(eventNameIndex + 1, entry.Length - eventNameIndex - 1).Trim();
ReadOnlySpan<char> suffixPart = entry.Slice(eventNameIndex + 1).Trim();
int samplingResultIndex = suffixPart.IndexOf('-');
if (samplingResultIndex >= 0)
{
// We have the format "[AS]SourceName/[EventName]-[SamplingResult]
eventName = suffixPart.Slice(0, samplingResultIndex).Trim();
suffixPart = suffixPart.Slice(samplingResultIndex + 1, suffixPart.Length - samplingResultIndex - 1).Trim();
suffixPart = suffixPart.Slice(samplingResultIndex + 1).Trim();

if (suffixPart.Length > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ internal static void GetDomainAndUsername(DirectoryContext context, out string?
if ((index = tmpUsername.IndexOf('\\')) != -1)
{
domain = tmpUsername.Substring(0, index);
username = tmpUsername.Substring(index + 1, tmpUsername.Length - index - 1);
username = tmpUsername.Substring(index + 1);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen(
if (styleIndex != -1)
{
// style found.
style = font.Substring(styleIndex, font.Length - styleIndex);
style = font.Substring(styleIndex);

// Get the mid-substring containing the size information.
sizeStr = font.Substring(nameIndex + 1, styleIndex - nameIndex - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public int Inflate(Span<byte> bytes)
}
if (copied > 0)
{
bytes = bytes.Slice(copied, bytes.Length - copied);
bytes = bytes.Slice(copied);
count += copied;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ internal static void ValidateXsiType(XmlReader reader, object ns, string name)
// The namespace of the prefix (string before ":") matches "ns"
// The name (string after ":") matches "name"
if (!object.ReferenceEquals(ns, reader.LookupNamespace(typeValue.Substring(0, index)))
|| string.CompareOrdinal(name, typeValue.Substring(index + 1, typeValue.Length - index - 1)) != 0)
|| string.CompareOrdinal(name, typeValue.Substring(index + 1)) != 0)
{
throw new XmlException(SR.Format(SR.UnknownDCDateTimeXsiType, reader.Name),
null, ((IXmlLineInfo)reader).LineNumber, ((IXmlLineInfo)reader).LinePosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static string ToDmtfDateTime(DateTime date)
else
{
string strTemp = OffsetMins.ToString(frmInt32);
UtcString = "-" + strTemp.Substring(1, strTemp.Length - 1).PadLeft(3, '0');
UtcString = "-" + strTemp.Substring(1).PadLeft(3, '0');
}

string dmtfDateTime = date.Year.ToString(frmInt32).PadLeft(4, '0');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ private string ResolveCollision(string inString, bool bCheckthisFirst)
if (strTemp.Length > 0)
{
string strFirstChar = strTemp.Substring(0, 1).ToUpperInvariant();
strTemp = strFirstChar + strTemp.Substring(1, strTemp.Length - 1);
strTemp = strFirstChar + strTemp.Substring(1);
}

return strTemp;
Expand Down Expand Up @@ -7142,7 +7142,7 @@ private void AddToDMTFDateTimeFunction()
else
{
string strTemp = OffsetMins.ToString();
UtcString = "-" + strTemp.Substring(1, strTemp.Length-1).PadLeft(3,'0');
UtcString = "-" + strTemp.Substring(1).PadLeft(3,'0');
}
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private static bool TryDecode5987(string input, out string? output)
}

string encodingString = input.Substring(0, quoteIndex);
string dataString = input.Substring(lastQuoteIndex + 1, input.Length - (lastQuoteIndex + 1));
string dataString = input.Substring(lastQuoteIndex + 1);

StringBuilder decoded = new StringBuilder();
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ private static void GetPathInfo(GetPathOption pathOption,
else
{
directory = path.Substring(0, index + 1);
filename = path.Substring(index + 1, path.Length - (index + 1));
filename = path.Substring(index + 1);
}

// strip off trailing '/' on directory if present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ internal FtpWebRequest(Uri uri)
{
username = Uri.UnescapeDataString(userInfo.Substring(0, index));
index++; // skip ':'
password = Uri.UnescapeDataString(userInfo.Substring(index, userInfo.Length - index));
password = Uri.UnescapeDataString(userInfo.Substring(index));
}
networkCredential = new NetworkCredential(username, password);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ private async ValueTask EnsureBufferContainsAsync(int minimumRequiredBytes, Canc
// While we don't have enough data, read more.
while (_receiveBufferCount < minimumRequiredBytes)
{
int numRead = await _stream.ReadAsync(_receiveBuffer.Slice(_receiveBufferCount, _receiveBuffer.Length - _receiveBufferCount), cancellationToken).ConfigureAwait(false);
int numRead = await _stream.ReadAsync(_receiveBuffer.Slice(_receiveBufferCount), cancellationToken).ConfigureAwait(false);
Debug.Assert(numRead >= 0, $"Expected non-negative bytes read, got {numRead}");
if (numRead <= 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Private.CoreLib/src/System/IO/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
for (int i = path.Length; --i >= 0;)
{
if (i < root || PathInternal.IsDirectorySeparator(path[i]))
return path.Slice(i + 1, path.Length - i - 1);
return path.Slice(i + 1);
}

return path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ private static void GetNameInAttributeScope(string? qualifiedName, XElement e, o
XNamespace? ns = e.GetNamespaceOfPrefix(qualifiedName.Substring(0, i));
if (ns != null)
{
localName = qualifiedName.Substring(i + 1, qualifiedName.Length - i - 1);
localName = qualifiedName.Substring(i + 1);
namespaceName = ns.NamespaceName;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ internal static string XdrCanonizeUri(string uri, XmlNameTable nameTable, Schema

if (convert)
{
canonicalUri = nameTable.Add(string.Concat(uri.AsSpan(0, offset), uri.Substring(offset, uri.Length - offset).ToUpperInvariant()));
canonicalUri = nameTable.Add(string.Concat(uri.AsSpan(0, offset), uri.Substring(offset).ToUpperInvariant()));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ internal static void SplitQName(string name, out string prefix, out string lname
{
prefix = name.Substring(0, colonPos);
colonPos++; // move after colon
lname = name.Substring(colonPos, name.Length - colonPos);
lname = name.Substring(colonPos);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ internal static void WriteCryptoBinary(string name, int value, StringBuilder bui
start++;
}

WriteCryptoBinary(name, valBuf.Slice(start, valBuf.Length - start), builder);
WriteCryptoBinary(name, valBuf.Slice(start), builder);
}

internal static void WriteCryptoBinary(string name, ReadOnlySpan<byte> value, StringBuilder builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private static string GetFirstKeyAndParseRemainder(ref string registryPath)
if (index >= 0)
{
firstKey = registryPath.Substring(0, index);
registryPath = registryPath.Substring(index + 1, registryPath.Length - index - 1);
registryPath = registryPath.Substring(index + 1);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ private void LoadSapiDictationGrammar(SapiGrammar sapiGrammar, Uri uri, string r
// - Modify SAPI so LoadCmdFromFile works with dictation Uris.
// - Modify the engine and use a regular grammar with a special ruleref to dictation.
// - Call back to the Grammar and let it manage the loading activation.
string topicName = string.IsNullOrEmpty(uri.Fragment) ? null : uri.Fragment.Substring(1, uri.Fragment.Length - 1);
string topicName = string.IsNullOrEmpty(uri.Fragment) ? null : uri.Fragment.Substring(1);
sapiGrammar.LoadDictation(topicName, SPLOADOPTIONS.SPLO_STATIC);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private static string[] Split(Regex regex, string input, int count, int startat)
return new[] { input };
}

state.results.Add(input.Substring(state.prevat, input.Length - state.prevat));
state.results.Add(input.Substring(state.prevat));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public string Replace(Regex regex, string input, int count, int startat)
return input;
}

state.segments.Add(state.inputMemory.Slice(state.prevat, input.Length - state.prevat));
state.segments.Add(state.inputMemory.Slice(state.prevat));
}
else
{
Expand Down

0 comments on commit 52fd1a5

Please sign in to comment.