perf: use char overloads for StartsWith/EndsWith (S6610)

Use single character overloads instead of single-character string
overloads for better performance.
This commit is contained in:
admin 2025-12-18 16:17:37 -06:00
parent 6b67a1672c
commit 021fd9b55e
9 changed files with 15 additions and 15 deletions

View file

@ -42,7 +42,7 @@ public OsPath(string path, OsPathKind kind)
private static OsPathKind DetectPathKind(string path)
{
if (path.StartsWith("/"))
if (path.StartsWith('/'))
{
return OsPathKind.Unix;
}
@ -141,7 +141,7 @@ public bool IsRooted
if (IsUnixPath)
{
return _path.StartsWith("/");
return _path.StartsWith('/');
}
return false;
@ -246,7 +246,7 @@ private int GetFileNameIndex()
return -1;
}
if (_path.StartsWith("/") && index == 0)
if (_path.StartsWith('/') && index == 0)
{
index++;
}
@ -490,7 +490,7 @@ public bool Equals(OsPath other, bool ignoreTrailingSlash)
newFragments.Add(leftFragments[j]);
}
if (left.FullPath.EndsWith("\\") || left.FullPath.EndsWith("/"))
if (left.FullPath.EndsWith("\\") || left.FullPath.EndsWith('/'))
{
newFragments.Add(string.Empty);
}

View file

@ -418,7 +418,7 @@ private static bool IsPathValidForWindows(string path)
private static bool IsPathValidForNonWindows(string path)
{
return path.StartsWith("/");
return path.StartsWith('/');
}
}
}

View file

@ -11,7 +11,7 @@ public static bool IsValidUrl(this string path)
return false;
}
if (path.StartsWith(" ") || path.EndsWith(" "))
if (path.StartsWith(' ') || path.EndsWith(' '))
{
return false;
}

View file

@ -55,7 +55,7 @@ public static string BuildBaseUrl(bool useHttps, string host, int port, string u
{
var protocol = useHttps ? "https" : "http";
if (urlBase.IsNotNullOrWhiteSpace() && !urlBase.StartsWith("/"))
if (urlBase.IsNotNullOrWhiteSpace() && !urlBase.StartsWith('/'))
{
urlBase = "/" + urlBase;
}
@ -239,7 +239,7 @@ protected virtual void ApplyFormData(HttpRequest request)
public virtual HttpRequestBuilder Resource(string resourceUrl)
{
if (!ResourceUrl.IsNotNullOrWhiteSpace() || resourceUrl.StartsWith("/"))
if (!ResourceUrl.IsNotNullOrWhiteSpace() || resourceUrl.StartsWith('/'))
{
ResourceUrl = resourceUrl.TrimStart('/');
}

View file

@ -43,7 +43,7 @@ public HttpUri(string scheme, string host, int? port, string path, string query,
if (path.IsNotNullOrWhiteSpace())
{
if (host.IsNotNullOrWhiteSpace() || path.StartsWith("/"))
if (host.IsNotNullOrWhiteSpace() || path.StartsWith('/'))
{
builder.Append('/');
}
@ -161,7 +161,7 @@ private static string CombineRelativePath(string basePath, string relativePath)
return basePath;
}
if (relativePath.StartsWith("/"))
if (relativePath.StartsWith('/'))
{
return relativePath;
}

View file

@ -21,7 +21,7 @@ private IEnumerable<ImportListRequest> GetMovies(string searchParameters)
var urlBase = "";
if (!string.IsNullOrWhiteSpace(Settings.UrlBase))
{
urlBase = Settings.UrlBase.StartsWith("/") ? Settings.UrlBase : $"/{Settings.UrlBase}";
urlBase = Settings.UrlBase.StartsWith('/') ? Settings.UrlBase : $"/{Settings.UrlBase}";
}
var status = "";

View file

@ -96,7 +96,7 @@ private void ValidateMapping(List<RemotePathMapping> existing, RemotePathMapping
throw new ArgumentException("Invalid Host");
}
if (mapping.RemotePath.StartsWith(" "))
if (mapping.RemotePath.StartsWith(' '))
{
throw new ArgumentException("Remote Path must not start with a space");
}

View file

@ -110,7 +110,7 @@ private IMount ParseLine(string line)
var type = split[2];
var options = ParseOptions(split[3]);
if (!mount.StartsWith("/"))
if (!mount.StartsWith('/'))
{
// Possible a namespace like 'net:[1234]'.
// But we just filter anything not starting with /, we're not interested in anything that isn't mounted somewhere.

View file

@ -29,11 +29,11 @@ public RemotePathMappingController(IRemotePathMappingService remotePathMappingSe
.NotEmpty();
SharedValidator.RuleFor(c => c.RemotePath)
.Must(remotePath => remotePath.IsNotNullOrWhiteSpace() && !remotePath.StartsWith(" "))
.Must(remotePath => remotePath.IsNotNullOrWhiteSpace() && !remotePath.StartsWith(' '))
.WithMessage("Remote Path '{PropertyValue}' must not start with a space");
SharedValidator.RuleFor(c => c.RemotePath)
.Must(remotePath => remotePath.IsNotNullOrWhiteSpace() && !remotePath.EndsWith(" "))
.Must(remotePath => remotePath.IsNotNullOrWhiteSpace() && !remotePath.EndsWith(' '))
.WithMessage("Remote Path '{PropertyValue}' must not end with a space");
SharedValidator.RuleFor(c => c.LocalPath)