make use of spans in UriExtensions to make them faster

This commit is contained in:
CyberReiter
2022-10-05 08:00:36 +02:00
committed by Sebastiaan Janssen
parent 7ad1e638e6
commit 02dcf98e3d

View File

@@ -1,6 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using System.Net;
using System.Web;
using Umbraco.Cms.Core;
@@ -75,14 +76,14 @@ public static class UriExtensions
}
// cannot get .AbsolutePath on relative uri (InvalidOperation)
var s = uri.OriginalString;
var s = uri.OriginalString.AsSpan();
// TODO: Shouldn't this just use Uri.GetLeftPart?
var posq = s.IndexOf("?", StringComparison.Ordinal);
var posf = s.IndexOf("#", StringComparison.Ordinal);
var posq = s.IndexOf('?');
var posf = s.IndexOf('#');
var pos = posq > 0 ? posq : posf > 0 ? posf : 0;
var path = pos > 0 ? s.Substring(0, pos) : s;
return path;
var path = pos > 0 ? s[..pos] : s;
return new string(path);
}
/// <summary>
@@ -188,12 +189,12 @@ public static class UriExtensions
}
// cannot get .Query on relative uri (InvalidOperation)
var s = uri.OriginalString;
var posq = s.IndexOf("?", StringComparison.Ordinal);
var posf = s.IndexOf("#", StringComparison.Ordinal);
var query = posq < 0 ? null : (posf < 0 ? s.Substring(posq) : s.Substring(posq, posf - posq));
var s = uri.OriginalString.AsSpan();
var posq = s.IndexOf('?');
var posf = s.IndexOf('#');
var query = posq < 0 ? null : (posf < 0 ? s[posq..] : s.Slice(posq, posf - posq));
return query;
return new string(query);
}
/// <summary>