From 1c048bdfc7b7e4dc9b6d8170b63052695b1d8459 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Tue, 19 May 2020 15:39:51 +0200 Subject: [PATCH] Checking strings against length seem to have better perf (#36443) * Chckecing strings against length seem to have better perf * Apply suggestions from code review Co-authored-by: Miha Zupan Co-authored-by: Ben Adams * Apply suggestions from code review Co-authored-by: Ben Adams * Update src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs Co-authored-by: Ben Adams * Apply suggestions from code review * Update src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameFormatter.cs * fix build error * Update SmtpClient.cs * Update AssemblyNameFormatter.cs * Update LoggingEventSource.cs * Fix build error * Apply suggestions from code review * Update src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationContent.cs * Fix build error * Apply suggestions from code review Co-authored-by: Miha Zupan Co-authored-by: Ben Adams --- .../Interop/Linux/cgroups/Interop.cgroups.cs | 2 +- .../System/Diagnostics/PerformanceCounter.cs | 4 ++-- .../Diagnostics/PerformanceCounterLib.cs | 2 +- .../src/System/Diagnostics/Process.Windows.cs | 2 +- .../src/System/Drawing/BitmapSelector.cs | 2 +- .../IO/IsolatedStorage/IsolatedStorageFile.cs | 22 +++++++++---------- .../InternalRelationshipCollection.cs | 2 +- .../Packaging/PackUriHelper.PackUriScheme.cs | 4 ++-- .../src/System/IO/Packaging/PackUriHelper.cs | 6 ++--- .../src/System/IO/Packaging/ZipPackage.cs | 2 +- .../src/System/Net/Mail/Attachment.cs | 8 +++---- .../src/System/Net/Mail/MailAddress.cs | 2 +- .../System/Net/Mail/MailAddressCollection.cs | 2 +- .../src/System/Net/Mail/MailMessage.cs | 4 ++-- .../src/System/Net/Mail/MailPriority.cs | 4 ++-- .../src/System/Net/Mail/SmtpClient.cs | 2 +- .../src/System/Net/Mime/ContentDisposition.cs | 2 +- .../src/System/Net/Mime/ContentType.cs | 8 +++---- .../src/System/Net/Mime/HeaderCollection.cs | 14 ++++++------ .../src/System/Net/FtpControlStream.cs | 2 +- .../Reflection/AssemblyNameFormatter.cs | 2 +- .../Serialization/Json/XmlJsonWriter.cs | 2 +- .../src/System/Xml/Dom/XmlNodeReader.cs | 2 +- .../src/System/Xml/Schema/XmlSchemaSet.cs | 2 +- .../src/System/Runtime/Caching/MemoryCache.cs | 4 ++-- .../Reflection/Emit/ModuleBuilder.Mono.cs | 2 +- .../src/System/Reflection/RuntimeModule.cs | 2 +- .../src/System/RuntimeTypeHandle.cs | 2 +- 28 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs b/src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs index abb7baa63a673..f2417e20881bd 100644 --- a/src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs +++ b/src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs @@ -348,7 +348,7 @@ internal static bool TryFindCGroupPathForSubsystem(CGroupVersion cgroupVersion, // cgroup v2: Find the first entry that matches the cgroup v2 hierarchy: // 0::$PATH - if ((lineParts[0] == "0") && (lineParts[1] == string.Empty)) + if ((lineParts[0] == "0") && (lineParts[1].Length == 0)) { path = lineParts[2]; return true; diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounter.cs b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounter.cs index f1637f4998c36..37e4b41d98a4f 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounter.cs +++ b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounter.cs @@ -470,9 +470,9 @@ private void InitializeImpl() string currentCategoryName = _categoryName; string currentMachineName = _machineName; - if (currentCategoryName == string.Empty) + if (currentCategoryName.Length == 0) throw new InvalidOperationException(SR.CategoryNameMissing); - if (_counterName == string.Empty) + if (_counterName.Length == 0) throw new InvalidOperationException(SR.CounterNameMissing); if (ReadOnly) diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs index 93ad673af15cb..7facea0fcdd6c 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs +++ b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs @@ -455,7 +455,7 @@ private static void CreateIniFile(string categoryName, string categoryHelp, Coun iniWriter.Write(languageId); iniWriter.Write(HelpSufix); iniWriter.Write("="); - if (categoryHelp == null || categoryHelp == string.Empty) + if (string.IsNullOrEmpty(categoryHelp)) iniWriter.WriteLine(SR.HelpNotAvailable); else iniWriter.WriteLine(categoryHelp); diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs index 998ec9fa03f5c..af85258d6a9ea 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs @@ -536,7 +536,7 @@ private unsafe bool StartWithCreateProcess(ProcessStartInfo startInfo) environmentBlock = GetEnvironmentVariablesBlock(startInfo._environmentVariables!); } string workingDirectory = startInfo.WorkingDirectory; - if (workingDirectory == string.Empty) + if (workingDirectory.Length == 0) workingDirectory = Directory.GetCurrentDirectory(); bool retVal; diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs index 06ccdf8e3c9c5..ae11c6e29d640 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs @@ -64,7 +64,7 @@ internal static string AppendSuffix(string filePath) /// public static string GetFileName(string originalPath) { - if (Suffix == string.Empty) + if (string.IsNullOrEmpty(Suffix)) return originalPath; string newPath = AppendSuffix(originalPath); diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs index d7d09f9bf3ff6..1d13427bb6659 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs @@ -262,7 +262,7 @@ public DateTimeOffset GetCreationTime(string path) if (path == null) throw new ArgumentNullException(nameof(path)); - if (path == string.Empty) + if (path.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(path)); } @@ -284,7 +284,7 @@ public DateTimeOffset GetLastAccessTime(string path) if (path == null) throw new ArgumentNullException(nameof(path)); - if (path == string.Empty) + if (path.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(path)); } @@ -306,7 +306,7 @@ public DateTimeOffset GetLastWriteTime(string path) if (path == null) throw new ArgumentNullException(nameof(path)); - if (path == string.Empty) + if (path.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(path)); } @@ -331,12 +331,12 @@ public void CopyFile(string sourceFileName, string destinationFileName) if (destinationFileName == null) throw new ArgumentNullException(nameof(destinationFileName)); - if (sourceFileName == string.Empty) + if (sourceFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(sourceFileName)); } - if (destinationFileName == string.Empty) + if (destinationFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(destinationFileName)); } @@ -352,12 +352,12 @@ public void CopyFile(string sourceFileName, string destinationFileName, bool ove if (destinationFileName == null) throw new ArgumentNullException(nameof(destinationFileName)); - if (sourceFileName == string.Empty) + if (sourceFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(sourceFileName)); } - if (destinationFileName == string.Empty) + if (destinationFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(destinationFileName)); } @@ -393,12 +393,12 @@ public void MoveFile(string sourceFileName, string destinationFileName) if (destinationFileName == null) throw new ArgumentNullException(nameof(destinationFileName)); - if (sourceFileName == string.Empty) + if (sourceFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(sourceFileName)); } - if (destinationFileName == string.Empty) + if (destinationFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(destinationFileName)); } @@ -434,12 +434,12 @@ public void MoveDirectory(string sourceDirectoryName, string destinationDirector if (destinationDirectoryName == null) throw new ArgumentNullException(nameof(destinationDirectoryName)); - if (sourceDirectoryName == string.Empty) + if (sourceDirectoryName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(sourceDirectoryName)); } - if (destinationDirectoryName == string.Empty) + if (destinationDirectoryName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(destinationDirectoryName)); } diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs index 09413c8a38444..db8cdf81d8b8e 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs @@ -161,7 +161,7 @@ internal void Flush() internal static void ThrowIfInvalidRelationshipType(string relationshipType) { // Look for empty string or string with just spaces - if (relationshipType.Trim() == string.Empty) + if (string.IsNullOrWhiteSpace(relationshipType)) throw new ArgumentException(SR.InvalidRelationshipType); } diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs index c2c79ee231837..c43ca1ac61cd6 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs @@ -79,7 +79,7 @@ public static Uri Create(Uri packageUri, Uri partUri, string fragment) if (fragment != null) { - if (fragment == string.Empty || fragment[0] != '#') + if (fragment.Length == 0 || fragment[0] != '#') throw new ArgumentException(SR.Format(SR.FragmentMustStartWithHash, nameof(fragment))); } @@ -323,7 +323,7 @@ private static PackUriHelper.ValidatedPartUri GetPartUriComponent(Uri packUri) string partName = GetStringForPartUriFromAnyUri(packUri); - if (partName == string.Empty) + if (partName.Length == 0) return null; else return ValidatePartUri(new Uri(partName, UriKind.Relative)); diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs index 2b50ad0791ffa..404e5e6fe9e24 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs @@ -49,7 +49,7 @@ public static Uri CreatePartUri(Uri partUri) string partName = GetStringForPartUriFromAnyUri(resolvedUri); - if (partName == string.Empty) + if (partName.Length == 0) throw new ArgumentException(SR.PartUriIsEmpty); ThrowIfPartNameEndsWithSlash(partName); @@ -399,7 +399,7 @@ private static Exception GetExceptionIfPartUriInvalid(Uri partUri, out string pa //We need to make sure that the URI passed to us is not just "/" //"/" is a valid relative uri, but is not a valid partname - if (partName == string.Empty) + if (partName.Length == 0) return new ArgumentException(SR.PartUriIsEmpty); if (partName[0] != ForwardSlashChar) @@ -804,7 +804,7 @@ private bool IsRelationshipUri() // String.Split, will always return an empty string as the // first member in the array as the string starts with a "/" - Debug.Assert(segments.Length > 0 && segments[0] == string.Empty); + Debug.Assert(segments.Length > 0 && segments[0].Length == 0); //If the extension was not equal to .rels, we would have exited early. Debug.Assert(string.CompareOrdinal((Path.GetExtension(segments[segments.Length - 1])), RelationshipPartUpperCaseExtension) == 0); diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs index f044bf76c1682..f44daf64e07a0 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs @@ -964,7 +964,7 @@ private void ValidateXmlAttribute(string attributeName, string attributeValue, s ThrowIfXmlAttributeMissing(attributeName, attributeValue, tagName, reader); //Checking for empty attribute - if (attributeValue == string.Empty) + if (attributeValue.Length == 0) throw new XmlException(SR.Format(SR.RequiredAttributeEmpty, tagName, attributeName), null, ((IXmlLineInfo)reader).LineNumber, ((IXmlLineInfo)reader).LinePosition); } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/Attachment.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/Attachment.cs index 44e48f7fc9e3e..91ffd95551706 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/Attachment.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/Attachment.cs @@ -75,7 +75,7 @@ internal void SetContentFromFile(string fileName, ContentType? contentType) throw new ArgumentNullException(nameof(fileName)); } - if (fileName == string.Empty) + if (fileName.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(fileName)), nameof(fileName)); } @@ -91,7 +91,7 @@ internal void SetContentFromFile(string fileName, string? mediaType) throw new ArgumentNullException(nameof(fileName)); } - if (fileName == string.Empty) + if (fileName.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(fileName)), nameof(fileName)); } @@ -154,7 +154,7 @@ internal void SetContentFromString(string content, Encoding? encoding, string? m _part.Stream.Close(); } - if (mediaType == null || mediaType == string.Empty) + if (string.IsNullOrEmpty(mediaType)) { mediaType = MediaTypeNames.Text.Plain; } @@ -340,7 +340,7 @@ public Attachment(string fileName, string? mediaType) : public Attachment(string fileName, ContentType contentType) : base(fileName, contentType) { - if (contentType.Name == null || contentType.Name == string.Empty) + if (string.IsNullOrEmpty(contentType.Name)) { Name = Path.GetFileName(fileName); } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs index 9519b3f80d87c..76d97dd95f4e5 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs @@ -124,7 +124,7 @@ private static bool TryParse(string address, string? displayName, Encoding? disp { throw new ArgumentNullException(nameof(address)); } - if (address == string.Empty) + if (address.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(address)), nameof(address)); } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressCollection.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressCollection.cs index 5b1b687e30179..bc63f116fcea9 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressCollection.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressCollection.cs @@ -23,7 +23,7 @@ public void Add(string addresses) { throw new ArgumentNullException(nameof(addresses)); } - if (addresses == string.Empty) + if (addresses.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(addresses)), nameof(addresses)); } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailMessage.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailMessage.cs index 83eddcd9f755f..4bb5e9e8663d2 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailMessage.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailMessage.cs @@ -44,10 +44,10 @@ public MailMessage(string from, string to) if (to == null) throw new ArgumentNullException(nameof(to)); - if (from == string.Empty) + if (from.Length == 0) throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(from)), nameof(from)); - if (to == string.Empty) + if (to.Length == 0) throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(to)), nameof(to)); _message = new Message(from, to); diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailPriority.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailPriority.cs index 6c912e3239c25..ee4618cdd83c3 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailPriority.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailPriority.cs @@ -51,10 +51,10 @@ internal Message(string from, string to) : this() if (to == null) throw new ArgumentNullException(nameof(to)); - if (from == string.Empty) + if (from.Length == 0) throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(from)), nameof(from)); - if (to == string.Empty) + if (to.Length == 0) throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(to)), nameof(to)); _from = new MailAddress(from); diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs index 834b5ba0b8081..0def5723b3064 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs @@ -187,7 +187,7 @@ public string? Host throw new ArgumentNullException(nameof(value)); } - if (value == string.Empty) + if (value.Length == 0) { throw new ArgumentException(SR.net_emptystringset, nameof(value)); } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentDisposition.cs b/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentDisposition.cs index be078ae7edcdf..891d17ef06882 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentDisposition.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentDisposition.cs @@ -83,7 +83,7 @@ public string DispositionType { throw new ArgumentNullException(nameof(value)); } - if (value == string.Empty) + if (value.Length == 0) { throw new ArgumentException(SR.net_emptystringset, nameof(value)); } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentType.cs b/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentType.cs index d3a183fb3b31f..7394cfdd20c5e 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentType.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentType.cs @@ -50,7 +50,7 @@ public ContentType(string contentType) { throw new ArgumentNullException(nameof(contentType)); } - if (contentType == string.Empty) + if (contentType.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(contentType)), nameof(contentType)); } @@ -65,7 +65,7 @@ public string? Boundary get { return Parameters["boundary"]; } set { - if (value == null || value == string.Empty) + if (string.IsNullOrEmpty(value)) { Parameters.Remove("boundary"); } @@ -81,7 +81,7 @@ public string? CharSet get { return Parameters["charset"]; } set { - if (value == null || value == string.Empty) + if (string.IsNullOrEmpty(value)) { Parameters.Remove("charset"); } @@ -105,7 +105,7 @@ public string MediaType throw new ArgumentNullException(nameof(value)); } - if (value == string.Empty) + if (value.Length == 0) { throw new ArgumentException(SR.net_emptystringset, nameof(value)); } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mime/HeaderCollection.cs b/src/libraries/System.Net.Mail/src/System/Net/Mime/HeaderCollection.cs index 1162b0138015f..1b468f725477f 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mime/HeaderCollection.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mime/HeaderCollection.cs @@ -31,7 +31,7 @@ public override void Remove(string name) throw new ArgumentNullException(nameof(name)); } - if (name == string.Empty) + if (name.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(name)), nameof(name)); } @@ -60,7 +60,7 @@ public override void Remove(string name) throw new ArgumentNullException(nameof(name)); } - if (name == string.Empty) + if (name.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(name)), nameof(name)); } @@ -87,7 +87,7 @@ public override void Remove(string name) throw new ArgumentNullException(nameof(name)); } - if (name == string.Empty) + if (name.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(name)), nameof(name)); } @@ -138,12 +138,12 @@ public override void Set(string name, string value) throw new ArgumentNullException(nameof(value)); } - if (name == string.Empty) + if (name.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(name)), nameof(name)); } - if (value == string.Empty) + if (value.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(value)), nameof(value)); } @@ -187,11 +187,11 @@ public override void Add(string name, string value) { throw new ArgumentNullException(nameof(value)); } - if (name == string.Empty) + if (name.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(name)), nameof(name)); } - if (value == string.Empty) + if (value.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(value)), nameof(value)); } diff --git a/src/libraries/System.Net.Requests/src/System/Net/FtpControlStream.cs b/src/libraries/System.Net.Requests/src/System/Net/FtpControlStream.cs index f36b48483d54a..3cd68e4ad068b 100644 --- a/src/libraries/System.Net.Requests/src/System/Net/FtpControlStream.cs +++ b/src/libraries/System.Net.Requests/src/System/Net/FtpControlStream.cs @@ -595,7 +595,7 @@ protected override PipelineEntry[] BuildCommandsList(WebRequest req) if (request.MethodInfo.Operation == FtpOperation.Rename) { - string baseDir = (requestDirectory == string.Empty) + string baseDir = (requestDirectory.Length == 0) ? string.Empty : requestDirectory + "/"; commandList.Add(new PipelineEntry(FormatFtpCommand("RNFR", baseDir + requestFilename), flags)); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameFormatter.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameFormatter.cs index 09585f8d58f19..3ead4ce8e87f3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameFormatter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameFormatter.cs @@ -54,7 +54,7 @@ public static string ComputeDisplayName(string? name, Version? version, string? if (cultureName != null) { - if (cultureName == string.Empty) + if (cultureName.Length == 0) cultureName = "neutral"; sb.Append(", Culture="); sb.AppendQuoted(cultureName); diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlJsonWriter.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlJsonWriter.cs index 6f09bd393b63b..2f0194b2334b6 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlJsonWriter.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlJsonWriter.cs @@ -245,7 +245,7 @@ public override string LookupPrefix(string ns) { return JsonGlobals.xmlPrefix; } - if (ns == string.Empty) + if (ns.Length == 0) { return string.Empty; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNodeReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNodeReader.cs index e8290112ad098..9d73bfa51103a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNodeReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNodeReader.cs @@ -919,7 +919,7 @@ internal string LookupPrefix(string namespaceName) { return _nameTable.Add("xml"); } - if (namespaceName == string.Empty) + if (namespaceName.Length == 0) { return string.Empty; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaSet.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaSet.cs index c071cdaf6a699..e9d9f7e9ad91f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaSet.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaSet.cs @@ -958,7 +958,7 @@ internal XmlSchema FindSchemaByNSAndUrl(Uri schemaUri, string ns, DictionaryEntr { return schema; } - else if (tns == string.Empty) + else if (tns.Length == 0) { //There could be a chameleon for same ns // It is OK to pass in the schema we have found so far, since it must have the schemaUri we're looking for // (we found it that way above) and it must be the original chameleon schema (the one without target ns) diff --git a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryCache.cs b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryCache.cs index 3dcbf43fecb9c..ffb420c4f7238 100644 --- a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryCache.cs +++ b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryCache.cs @@ -344,7 +344,7 @@ public MemoryCache(string name, NameValueCollection config = null) { throw new ArgumentNullException(nameof(name)); } - if (name == string.Empty) + if (name.Length == 0) { throw new ArgumentException(SR.Empty_string_invalid, nameof(name)); } @@ -364,7 +364,7 @@ public MemoryCache(string name, NameValueCollection config, bool ignoreConfigSec { throw new ArgumentNullException(nameof(name)); } - if (name == string.Empty) + if (name.Length == 0) { throw new ArgumentException(SR.Empty_string_invalid, nameof(name)); } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs index 0c9f12ad193aa..5f6e79e580c33 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs @@ -154,7 +154,7 @@ private FieldBuilder DefineDataImpl(string name, int size, FieldAttributes attri { if (name == null) throw new ArgumentNullException(nameof(name)); - if (name == string.Empty) + if (name.Length == 0) throw new ArgumentException("name cannot be empty", nameof(name)); if (global_type_created != null) throw new InvalidOperationException("global fields already created"); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs index 5d110fefdaebb..d4efac98e0a4e 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs @@ -197,7 +197,7 @@ Type GetType(string className, bool throwOnError, bool ignoreCase) { if (className == null) throw new ArgumentNullException(nameof(className)); - if (className == string.Empty) + if (className.Length == 0) throw new ArgumentException("Type name can't be empty"); return assembly.InternalGetType(this, className, throwOnError, ignoreCase); } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index 7df75e09b9178..90a36a0230f5c 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -289,7 +289,7 @@ internal static bool IsTypeDefinition(RuntimeType type) if (typeName == null) throw new ArgumentNullException(nameof(typeName)); - if (typeName == string.Empty) + if (typeName.Length == 0) if (throwOnError) throw new TypeLoadException("A null or zero length string does not represent a valid Type."); else