1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-23 01:44:22 +00:00

Minor string optimisation.

This commit is contained in:
jules 2012-08-09 08:54:43 +01:00
parent 0ce65462af
commit cf959decce
3 changed files with 14 additions and 3 deletions

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

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)));

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,