From 9d1f6abe49c5fc964b729a5ad43399cd715311b7 Mon Sep 17 00:00:00 2001 From: Tom Maisey Date: Tue, 2 Apr 2019 15:12:03 +0100 Subject: [PATCH] Avoided some allocations in StringRef/Identifier/String comparisons --- modules/juce_core/text/juce_String.cpp | 8 ++++---- modules/juce_core/text/juce_String.h | 9 --------- modules/juce_core/text/juce_StringRef.h | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index f0cd2db870..deee114b10 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -566,16 +566,16 @@ JUCE_API bool JUCE_CALLTYPE operator== (const String& s1, const wchar_t* s2) noe JUCE_API bool JUCE_CALLTYPE operator!= (const String& s1, const wchar_t* s2) noexcept { return s1.compare (s2) != 0; } JUCE_API bool JUCE_CALLTYPE operator== (const String& s1, StringRef s2) noexcept { return s1.getCharPointer().compare (s2.text) == 0; } JUCE_API bool JUCE_CALLTYPE operator!= (const String& s1, StringRef s2) noexcept { return s1.getCharPointer().compare (s2.text) != 0; } +JUCE_API bool JUCE_CALLTYPE operator< (const String& s1, StringRef s2) noexcept { return s1.getCharPointer().compare (s2.text) < 0; } +JUCE_API bool JUCE_CALLTYPE operator<= (const String& s1, StringRef s2) noexcept { return s1.getCharPointer().compare (s2.text) <= 0; } +JUCE_API bool JUCE_CALLTYPE operator> (const String& s1, StringRef s2) noexcept { return s1.getCharPointer().compare (s2.text) > 0; } +JUCE_API bool JUCE_CALLTYPE operator>= (const String& s1, StringRef s2) noexcept { return s1.getCharPointer().compare (s2.text) >= 0; } JUCE_API bool JUCE_CALLTYPE operator== (const String& s1, const CharPointer_UTF8 s2) noexcept { return s1.getCharPointer().compare (s2) == 0; } JUCE_API bool JUCE_CALLTYPE operator!= (const String& s1, const CharPointer_UTF8 s2) noexcept { return s1.getCharPointer().compare (s2) != 0; } JUCE_API bool JUCE_CALLTYPE operator== (const String& s1, const CharPointer_UTF16 s2) noexcept { return s1.getCharPointer().compare (s2) == 0; } JUCE_API bool JUCE_CALLTYPE operator!= (const String& s1, const CharPointer_UTF16 s2) noexcept { return s1.getCharPointer().compare (s2) != 0; } JUCE_API bool JUCE_CALLTYPE operator== (const String& s1, const CharPointer_UTF32 s2) noexcept { return s1.getCharPointer().compare (s2) == 0; } JUCE_API bool JUCE_CALLTYPE operator!= (const String& s1, const CharPointer_UTF32 s2) noexcept { return s1.getCharPointer().compare (s2) != 0; } -JUCE_API bool JUCE_CALLTYPE operator> (const String& s1, const String& s2) noexcept { return s1.compare (s2) > 0; } -JUCE_API bool JUCE_CALLTYPE operator< (const String& s1, const String& s2) noexcept { return s1.compare (s2) < 0; } -JUCE_API bool JUCE_CALLTYPE operator>= (const String& s1, const String& s2) noexcept { return s1.compare (s2) >= 0; } -JUCE_API bool JUCE_CALLTYPE operator<= (const String& s1, const String& s2) noexcept { return s1.compare (s2) <= 0; } bool String::equalsIgnoreCase (const wchar_t* const t) const noexcept { diff --git a/modules/juce_core/text/juce_String.h b/modules/juce_core/text/juce_String.h index b1acf00486..4e14b16f1d 100644 --- a/modules/juce_core/text/juce_String.h +++ b/modules/juce_core/text/juce_String.h @@ -1513,15 +1513,6 @@ JUCE_API bool JUCE_CALLTYPE operator!= (const String& string1, CharPointer_UTF16 /** Case-sensitive comparison of two strings. */ JUCE_API bool JUCE_CALLTYPE operator!= (const String& string1, CharPointer_UTF32 string2) noexcept; -/** Case-sensitive comparison of two strings. */ -JUCE_API bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) noexcept; -/** Case-sensitive comparison of two strings. */ -JUCE_API bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) noexcept; -/** Case-sensitive comparison of two strings. */ -JUCE_API bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) noexcept; -/** Case-sensitive comparison of two strings. */ -JUCE_API bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) noexcept; - //============================================================================== /** This operator allows you to write a juce String directly to std output streams. This is handy for writing strings to std::cout, std::cerr, etc. diff --git a/modules/juce_core/text/juce_StringRef.h b/modules/juce_core/text/juce_StringRef.h index 82bf4982d4..db2c726401 100644 --- a/modules/juce_core/text/juce_StringRef.h +++ b/modules/juce_core/text/juce_StringRef.h @@ -111,6 +111,14 @@ public: bool operator== (const String& s) const noexcept { return text.compare (s.getCharPointer()) == 0; } /** Compares this StringRef with a String. */ bool operator!= (const String& s) const noexcept { return text.compare (s.getCharPointer()) != 0; } + /** Compares this StringRef with a String. */ + bool operator< (const String& s) const noexcept { return text.compare (s.getCharPointer()) < 0; } + /** Compares this StringRef with a String. */ + bool operator<= (const String& s) const noexcept { return text.compare (s.getCharPointer()) <= 0; } + /** Compares this StringRef with a String. */ + bool operator> (const String& s) const noexcept { return text.compare (s.getCharPointer()) > 0; } + /** Compares this StringRef with a String. */ + bool operator>= (const String& s) const noexcept { return text.compare (s.getCharPointer()) >= 0; } /** Case-sensitive comparison of two StringRefs. */ bool operator== (StringRef s) const noexcept { return text.compare (s.text) == 0; } @@ -133,6 +141,14 @@ public: JUCE_API bool JUCE_CALLTYPE operator== (const String& string1, StringRef string2) noexcept; /** Case-sensitive comparison of two strings. */ JUCE_API bool JUCE_CALLTYPE operator!= (const String& string1, StringRef string2) noexcept; +/** Case-sensitive comparison of two strings. */ +JUCE_API bool JUCE_CALLTYPE operator< (const String& string1, StringRef string2) noexcept; +/** Case-sensitive comparison of two strings. */ +JUCE_API bool JUCE_CALLTYPE operator<= (const String& string1, StringRef string2) noexcept; +/** Case-sensitive comparison of two strings. */ +JUCE_API bool JUCE_CALLTYPE operator> (const String& string1, StringRef string2) noexcept; +/** Case-sensitive comparison of two strings. */ +JUCE_API bool JUCE_CALLTYPE operator>= (const String& string1, StringRef string2) noexcept; inline String operator+ (String s1, StringRef s2) { return s1 += String (s2.text); } inline String operator+ (StringRef s1, const String& s2) { return String (s1.text) + s2; }