Browse Source

Minor string optimisation.

tags/2021-05-28
jules 13 years ago
parent
commit
cf959decce
3 changed files with 14 additions and 3 deletions
  1. +1
    -1
      modules/juce_core/memory/juce_Memory.h
  2. +12
    -0
      modules/juce_core/text/juce_String.cpp
  3. +1
    -2
      modules/juce_gui_basics/native/juce_mac_MainMenu.mm

+ 1
- 1
modules/juce_core/memory/juce_Memory.h View File

@@ -65,7 +65,7 @@ inline int getAddressDifference (Type1* pointer1, Type2* pointer2) noexcept { r
nullptr if the pointer is null.
*/
template <class Type>
inline Type* createCopyIfNotNull (Type* pointer) { return pointer != nullptr ? new Type (*pointer) : nullptr; }
inline Type* createCopyIfNotNull (const Type* pointer) { return pointer != nullptr ? new Type (*pointer) : nullptr; }
//==============================================================================
#if JUCE_MAC || JUCE_IOS || DOXYGEN


+ 12
- 0
modules/juce_core/text/juce_String.cpp View File

@@ -128,6 +128,18 @@ public:
return dest;
}
static CharPointerType createFromCharPointer (const CharPointerType& start, const CharPointerType& end)
{
if (start.getAddress() == nullptr || start.isEmpty())
return getEmpty();
const size_t numBytes = end.getAddress() - start.getAddress();
const CharPointerType dest (createUninitialisedBytes (numBytes + 1));
memcpy (dest.getAddress(), start, numBytes);
dest.getAddress()[numBytes] = 0;
return dest;
}
static CharPointerType createFromFixedLength (const char* const src, const size_t numChars)
{
const CharPointerType dest (createUninitialisedBytes (numChars * sizeof (CharType) + sizeof (CharType)));


+ 1
- 2
modules/juce_gui_basics/native/juce_mac_MainMenu.mm View File

@@ -61,8 +61,7 @@ public:
menuBarItemsChanged (nullptr);
}
extraAppleMenuItems = newExtraAppleMenuItems != nullptr ? new PopupMenu (*newExtraAppleMenuItems)
: nullptr;
extraAppleMenuItems = createCopyIfNotNull (newExtraAppleMenuItems);
}
void addSubMenu (NSMenu* parent, const PopupMenu& child,


Loading…
Cancel
Save