make use of spans in UriExtensions to make them faster
(cherry picked from commit 02dcf98e3d)
This commit is contained in:
committed by
Sebastiaan Janssen
parent
57a29e4085
commit
328f5e0817
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user