From 3744efa6eafc8a4935bf5fac1b41b28f90f5d4ba Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Wed, 24 Aug 2011 20:25:36 +0100 Subject: [PATCH] Tweaked some timings for mac native menus. Minor clean-ups. --- modules/juce_core/text/juce_String.cpp | 92 +++++++------------ modules/juce_core/text/juce_String.h | 6 +- .../native/juce_mac_MainMenu.mm | 2 +- 3 files changed, 37 insertions(+), 63 deletions(-) diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index 34f00ceae2..7065cf1aa5 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -430,7 +430,7 @@ namespace NumberToStringConverters return dp; } - char* doubleToString (char* buffer, int numChars, double n, int numDecPlaces, size_t& len) noexcept + char* doubleToString (char* buffer, const int numChars, double n, int numDecPlaces, size_t& len) noexcept { if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20) { @@ -983,76 +983,50 @@ bool String::containsWholeWordIgnoreCase (const String& wordToLookFor) const noe } //============================================================================== -namespace WildCardHelpers +template +struct WildCardMatcher { - int indexOfMatch (const String::CharPointerType& wildcard, - String::CharPointerType test, - const bool ignoreCase) noexcept + static bool matches (CharPointer wildcard, CharPointer test, const bool ignoreCase) noexcept { - int start = 0; + for (;;) + { + const juce_wchar wc = *wildcard; + const juce_wchar tc = *test; + if (wc == tc + || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (tc)) + || (wc == '?' && tc != 0)) + { + if (wc == 0) + return true; + + ++test; + ++wildcard; + } + else + { + return wc == '*' && (wildcard[1] == 0 || matchesAnywhere (wildcard + 1, test, ignoreCase)); + } + } + } + + static bool matchesAnywhere (const CharPointer& wildcard, CharPointer test, const bool ignoreCase) noexcept + { while (! test.isEmpty()) { - String::CharPointerType t (test); - String::CharPointerType w (wildcard); + if (matches (wildcard, test, ignoreCase)) + return true; - for (;;) - { - const juce_wchar wc = *w; - const juce_wchar tc = *t; - - if (wc == tc - || (ignoreCase && w.toLowerCase() == t.toLowerCase()) - || (wc == '?' && tc != 0)) - { - if (wc == 0) - return start; - - ++t; - ++w; - } - else - { - if (wc == '*' && (w[1] == 0 || indexOfMatch (w + 1, t, ignoreCase) >= 0)) - return start; - - break; - } - } - - ++start; ++test; } - return -1; + return false; } -} +}; bool String::matchesWildcard (const String& wildcard, const bool ignoreCase) const noexcept { - CharPointerType w (wildcard.text); - CharPointerType t (text); - - for (;;) - { - const juce_wchar wc = *w; - const juce_wchar tc = *t; - - if (wc == tc - || (ignoreCase && w.toLowerCase() == t.toLowerCase()) - || (wc == '?' && tc != 0)) - { - if (wc == 0) - return true; - - ++w; - ++t; - } - else - { - return wc == '*' && (w[1] == 0 || WildCardHelpers::indexOfMatch (w + 1, t, ignoreCase) >= 0); - } - } + return WildCardMatcher::matches (wildcard.text, text, ignoreCase); } //============================================================================== @@ -2090,7 +2064,7 @@ String String::fromUTF8 (const char* const buffer, int bufferSizeBytes) } #if JUCE_MSVC - #pragma warning (pop) + #pragma warning (pop) #endif //============================================================================== diff --git a/modules/juce_core/text/juce_String.h b/modules/juce_core/text/juce_String.h index 7153b5fce7..fb7d5b2148 100644 --- a/modules/juce_core/text/juce_String.h +++ b/modules/juce_core/text/juce_String.h @@ -33,8 +33,8 @@ #endif #if JUCE_MSVC - #pragma warning (push) - #pragma warning (disable: 4514 4996) + #pragma warning (push) + #pragma warning (disable: 4514 4996) #endif #include "../memory/juce_Atomic.h" @@ -44,7 +44,7 @@ #include "juce_CharPointer_ASCII.h" #if JUCE_MSVC - #pragma warning (pop) + #pragma warning (pop) #endif class OutputStream; diff --git a/modules/juce_gui_basics/native/juce_mac_MainMenu.mm b/modules/juce_gui_basics/native/juce_mac_MainMenu.mm index 1b0fc5ef3f..58c7eb9abe 100644 --- a/modules/juce_gui_basics/native/juce_mac_MainMenu.mm +++ b/modules/juce_gui_basics/native/juce_mac_MainMenu.mm @@ -163,7 +163,7 @@ public: [menu performSelector: @selector (cancelTracking)]; } - if (Time::getMillisecondCounter() > lastUpdateTime + 500) + if (Time::getMillisecondCounter() > lastUpdateTime + 100) (new AsyncMenuUpdater())->post(); }