Bug 2051711 - Add operator<=> to nsTStringRepr. r=xpcom-reviewers,webrtc-reviewers,bwc,emilio

Differential Revision: https://phabricator.services.mozilla.com/D309690
This commit is contained in:
Andreas Pehrson
2026-08-27 07:59:44 +00:00
committed by pehrsons@gmail.com
parent 188f6186e6
commit 1edbfdef65
3 changed files with 24 additions and 24 deletions
@@ -13,9 +13,7 @@ namespace mozilla {
static std::strong_ordering RtpExtensionHeaderUriComparator(
const PeerConnectionImpl::RtpExtensionHeader& aHeader, const char* aUri) {
// TODO bug 2051711: use nsCString::operator<=> directly.
return std::string_view(aHeader.extensionname.get()) <=>
std::string_view(aUri);
return aHeader.extensionname <=> nsDependentCString(aUri);
}
static const PeerConnectionImpl::RtpExtensionHeader* FindExtension(
+4 -21
View File
@@ -525,18 +525,6 @@ inline constexpr bool operator!=(const mozilla::detail::nsTStringRepr<T>& aLhs,
return !aLhs.Equals(aRhs);
}
template <typename T>
inline bool operator<(const mozilla::detail::nsTStringRepr<T>& aLhs,
const mozilla::detail::nsTStringRepr<T>& aRhs) {
return Compare(aLhs, aRhs) < 0;
}
template <typename T>
inline bool operator<=(const mozilla::detail::nsTStringRepr<T>& aLhs,
const mozilla::detail::nsTStringRepr<T>& aRhs) {
return Compare(aLhs, aRhs) <= 0;
}
template <typename T>
inline bool operator==(const mozilla::detail::nsTStringRepr<T>& aLhs,
const mozilla::detail::nsTStringRepr<T>& aRhs) {
@@ -550,15 +538,10 @@ inline bool operator==(const mozilla::detail::nsTStringRepr<T>& aLhs,
}
template <typename T>
inline bool operator>=(const mozilla::detail::nsTStringRepr<T>& aLhs,
const mozilla::detail::nsTStringRepr<T>& aRhs) {
return Compare(aLhs, aRhs) >= 0;
}
template <typename T>
inline bool operator>(const mozilla::detail::nsTStringRepr<T>& aLhs,
const mozilla::detail::nsTStringRepr<T>& aRhs) {
return Compare(aLhs, aRhs) > 0;
inline std::strong_ordering operator<=>(
const mozilla::detail::nsTStringRepr<T>& aLhs,
const mozilla::detail::nsTStringRepr<T>& aRhs) {
return Compare(aLhs, aRhs) <=> 0;
}
template <typename Char>
+19
View File
@@ -2415,6 +2415,25 @@ TEST_F(Strings, printf) {
#undef verify_printf_strings
#undef create_printf_strings
TEST(String, SpaceshipCompare)
{
nsAutoCString a("A");
nsCString b("B");
EXPECT_EQ(a <=> a, std::strong_ordering::equal);
EXPECT_EQ(a <=> b, std::strong_ordering::less);
EXPECT_EQ(b <=> a, std::strong_ordering::greater);
EXPECT_EQ(b <=> b, std::strong_ordering::equal);
nsLiteralCString ab = "AB"_ns;
EXPECT_EQ(a <=> ab, std::strong_ordering::less);
EXPECT_EQ(b <=> ab, std::strong_ordering::greater);
a.Append("B");
EXPECT_EQ(a <=> a, std::strong_ordering::equal);
EXPECT_EQ(a <=> b, std::strong_ordering::less);
EXPECT_EQ(a <=> ab, std::strong_ordering::equal);
}
// Note the five calls in the loop, so divide by 100k
MOZ_GTEST_BENCH_F(Strings, PerfStripWhitespace, [this] {
nsCString test1(mExample1Utf8);