Browse Source

Optimised Array with some move-operators.

tags/2021-05-28
jules 12 years ago
parent
commit
18a012f7db
3 changed files with 29 additions and 3 deletions
  1. +17
    -3
      modules/juce_core/containers/juce_Array.h
  2. +7
    -0
      modules/juce_core/text/juce_StringArray.cpp
  3. +5
    -0
      modules/juce_core/text/juce_StringArray.h

+ 17
- 3
modules/juce_core/containers/juce_Array.h View File

@@ -85,7 +85,7 @@ public:
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
Array (Array<ElementType, TypeOfCriticalSectionToUse>&& other) noexcept
: data (static_cast <ArrayAllocationBase<ElementType, TypeOfCriticalSectionToUse>&&> (other.data)),
: data (static_cast<ArrayAllocationBase<ElementType, TypeOfCriticalSectionToUse>&&> (other.data)),
numUsed (other.numUsed)
{
other.numUsed = 0;
@@ -143,7 +143,7 @@ public:
Array& operator= (Array&& other) noexcept
{
const ScopedLockType lock (getLock());
data = static_cast <ArrayAllocationBase<ElementType, TypeOfCriticalSectionToUse>&&> (other.data);
data = static_cast<ArrayAllocationBase<ElementType, TypeOfCriticalSectionToUse>&&> (other.data);
numUsed = other.numUsed;
other.numUsed = 0;
return *this;
@@ -369,13 +369,27 @@ public:
@param newElement the new object to add to the array
@see set, insert, addIfNotAlreadyThere, addSorted, addUsingDefaultSort, addArray
*/
void add (ParameterType newElement)
void add (const ElementType& newElement)
{
const ScopedLockType lock (getLock());
data.ensureAllocatedSize (numUsed + 1);
new (data.elements + numUsed++) ElementType (newElement);
}
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
/** Appends a new element at the end of the array.
@param newElement the new object to add to the array
@see set, insert, addIfNotAlreadyThere, addSorted, addUsingDefaultSort, addArray
*/
void add (ElementType&& newElement)
{
const ScopedLockType lock (getLock());
data.ensureAllocatedSize (numUsed + 1);
new (data.elements + numUsed++) ElementType (static_cast<ElementType&&> (newElement));
}
#endif
/** Inserts a new element into the array at a given position.
If the index is less than 0 or greater than the size of the array, the


+ 7
- 0
modules/juce_core/text/juce_StringArray.cpp View File

@@ -133,6 +133,13 @@ void StringArray::add (const String& newString)
strings.add (newString);
}
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
void StringArray::add (String&& stringToAdd)
{
strings.add (static_cast<String&&> (stringToAdd));
}
#endif
void StringArray::insert (const int index, const String& newString)
{
strings.insert (index, newString);


+ 5
- 0
modules/juce_core/text/juce_StringArray.h View File

@@ -174,6 +174,11 @@ public:
/** Appends a string at the end of the array. */
void add (const String& stringToAdd);
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
/** Appends a string at the end of the array. */
void add (String&& stringToAdd);
#endif
/** Inserts a string into the array.
This will insert a string into the array at the given index, moving


Loading…
Cancel
Save