| @@ -187,7 +187,7 @@ public: | |||||
| return false; | return false; | ||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| if (! (data.elements [i] == other.data.elements [i])) | |||||
| if (! (data.elements[i] == other.data.elements[i])) | |||||
| return false; | return false; | ||||
| return true; | return true; | ||||
| @@ -249,7 +249,7 @@ public: | |||||
| /** Returns true if the array is empty, false otherwise. */ | /** Returns true if the array is empty, false otherwise. */ | ||||
| inline bool isEmpty() const noexcept | inline bool isEmpty() const noexcept | ||||
| { | { | ||||
| return size() == 0; | |||||
| return numUsed == 0; | |||||
| } | } | ||||
| /** Returns one of the elements in the array. | /** Returns one of the elements in the array. | ||||
| @@ -269,7 +269,7 @@ public: | |||||
| if (isPositiveAndBelow (index, numUsed)) | if (isPositiveAndBelow (index, numUsed)) | ||||
| { | { | ||||
| jassert (data.elements != nullptr); | jassert (data.elements != nullptr); | ||||
| return data.elements [index]; | |||||
| return data.elements[index]; | |||||
| } | } | ||||
| return ElementType(); | return ElementType(); | ||||
| @@ -288,7 +288,7 @@ public: | |||||
| { | { | ||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| jassert (isPositiveAndBelow (index, numUsed) && data.elements != nullptr); | jassert (isPositiveAndBelow (index, numUsed) && data.elements != nullptr); | ||||
| return data.elements [index]; | |||||
| return data.elements[index]; | |||||
| } | } | ||||
| /** Returns a direct reference to one of the elements in the array, without checking the index passed in. | /** Returns a direct reference to one of the elements in the array, without checking the index passed in. | ||||
| @@ -304,11 +304,10 @@ public: | |||||
| { | { | ||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| jassert (isPositiveAndBelow (index, numUsed) && data.elements != nullptr); | jassert (isPositiveAndBelow (index, numUsed) && data.elements != nullptr); | ||||
| return data.elements [index]; | |||||
| return data.elements[index]; | |||||
| } | } | ||||
| /** Returns the first element in the array, or a default value if the array is empty. | /** Returns the first element in the array, or a default value if the array is empty. | ||||
| @see operator[], getUnchecked, getLast | @see operator[], getUnchecked, getLast | ||||
| */ | */ | ||||
| inline ElementType getFirst() const | inline ElementType getFirst() const | ||||
| @@ -384,10 +383,10 @@ public: | |||||
| int indexOf (ParameterType elementToLookFor) const | int indexOf (ParameterType elementToLookFor) const | ||||
| { | { | ||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| const ElementType* e = data.elements.get(); | |||||
| const ElementType* const end_ = e + numUsed; | |||||
| auto e = data.elements.get(); | |||||
| auto endPtr = e + numUsed; | |||||
| for (; e != end_; ++e) | |||||
| for (; e != endPtr; ++e) | |||||
| if (elementToLookFor == *e) | if (elementToLookFor == *e) | ||||
| return static_cast<int> (e - data.elements.get()); | return static_cast<int> (e - data.elements.get()); | ||||
| @@ -402,10 +401,10 @@ public: | |||||
| bool contains (ParameterType elementToLookFor) const | bool contains (ParameterType elementToLookFor) const | ||||
| { | { | ||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| const ElementType* e = data.elements.get(); | |||||
| const ElementType* const end_ = e + numUsed; | |||||
| auto e = data.elements.get(); | |||||
| auto endPtr = e + numUsed; | |||||
| for (; e != end_; ++e) | |||||
| for (; e != endPtr; ++e) | |||||
| if (elementToLookFor == *e) | if (elementToLookFor == *e) | ||||
| return true; | return true; | ||||
| @@ -473,8 +472,8 @@ public: | |||||
| if (isPositiveAndBelow (indexToInsertAt, numUsed)) | if (isPositiveAndBelow (indexToInsertAt, numUsed)) | ||||
| { | { | ||||
| ElementType* const insertPos = data.elements + indexToInsertAt; | |||||
| const int numberToMove = numUsed - indexToInsertAt; | |||||
| auto* insertPos = data.elements + indexToInsertAt; | |||||
| auto numberToMove = numUsed - indexToInsertAt; | |||||
| if (numberToMove > 0) | if (numberToMove > 0) | ||||
| memmove (insertPos + 1, insertPos, ((size_t) numberToMove) * sizeof (ElementType)); | memmove (insertPos + 1, insertPos, ((size_t) numberToMove) * sizeof (ElementType)); | ||||
| @@ -512,7 +511,7 @@ public: | |||||
| if (isPositiveAndBelow (indexToInsertAt, numUsed)) | if (isPositiveAndBelow (indexToInsertAt, numUsed)) | ||||
| { | { | ||||
| insertPos = data.elements + indexToInsertAt; | insertPos = data.elements + indexToInsertAt; | ||||
| const int numberToMove = numUsed - indexToInsertAt; | |||||
| auto numberToMove = numUsed - indexToInsertAt; | |||||
| memmove (insertPos + numberOfTimesToInsertIt, insertPos, ((size_t) numberToMove) * sizeof (ElementType)); | memmove (insertPos + numberOfTimesToInsertIt, insertPos, ((size_t) numberToMove) * sizeof (ElementType)); | ||||
| } | } | ||||
| else | else | ||||
| @@ -556,7 +555,7 @@ public: | |||||
| if (isPositiveAndBelow (indexToInsertAt, numUsed)) | if (isPositiveAndBelow (indexToInsertAt, numUsed)) | ||||
| { | { | ||||
| insertPos += indexToInsertAt; | insertPos += indexToInsertAt; | ||||
| const int numberToMove = numUsed - indexToInsertAt; | |||||
| auto numberToMove = numUsed - indexToInsertAt; | |||||
| memmove (insertPos + numberOfElements, insertPos, (size_t) numberToMove * sizeof (ElementType)); | memmove (insertPos + numberOfElements, insertPos, (size_t) numberToMove * sizeof (ElementType)); | ||||
| } | } | ||||
| else | else | ||||
| @@ -608,7 +607,7 @@ public: | |||||
| if (isPositiveAndBelow (indexToChange, numUsed)) | if (isPositiveAndBelow (indexToChange, numUsed)) | ||||
| { | { | ||||
| jassert (data.elements != nullptr); | jassert (data.elements != nullptr); | ||||
| data.elements [indexToChange] = newValue; | |||||
| data.elements[indexToChange] = newValue; | |||||
| } | } | ||||
| else if (indexToChange >= 0) | else if (indexToChange >= 0) | ||||
| { | { | ||||
| @@ -630,7 +629,7 @@ public: | |||||
| { | { | ||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| jassert (isPositiveAndBelow (indexToChange, numUsed)); | jassert (isPositiveAndBelow (indexToChange, numUsed)); | ||||
| data.elements [indexToChange] = newValue; | |||||
| data.elements[indexToChange] = newValue; | |||||
| } | } | ||||
| /** Adds elements from an array to the end of this array. | /** Adds elements from an array to the end of this array. | ||||
| @@ -682,7 +681,8 @@ public: | |||||
| void addNullTerminatedArray (const Type* const* elementsToAdd) | void addNullTerminatedArray (const Type* const* elementsToAdd) | ||||
| { | { | ||||
| int num = 0; | int num = 0; | ||||
| for (const Type* const* e = elementsToAdd; *e != nullptr; ++e) | |||||
| for (auto e = elementsToAdd; *e != nullptr; ++e) | |||||
| ++num; | ++num; | ||||
| addArray (elementsToAdd, num); | addArray (elementsToAdd, num); | ||||
| @@ -730,8 +730,10 @@ public: | |||||
| if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size()) | if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size()) | ||||
| numElementsToAdd = arrayToAddFrom.size() - startIndex; | numElementsToAdd = arrayToAddFrom.size() - startIndex; | ||||
| data.ensureAllocatedSize (numUsed + numElementsToAdd); | |||||
| while (--numElementsToAdd >= 0) | while (--numElementsToAdd >= 0) | ||||
| add (arrayToAddFrom.getUnchecked (startIndex++)); | |||||
| addAssumingCapacityIsReady (arrayToAddFrom.getUnchecked (startIndex++)); | |||||
| } | } | ||||
| } | } | ||||
| @@ -814,14 +816,15 @@ public: | |||||
| if (s >= e) | if (s >= e) | ||||
| return -1; | return -1; | ||||
| if (comparator.compareElements (elementToLookFor, data.elements [s]) == 0) | |||||
| if (comparator.compareElements (elementToLookFor, data.elements[s]) == 0) | |||||
| return s; | return s; | ||||
| const int halfway = (s + e) / 2; | |||||
| auto halfway = (s + e) / 2; | |||||
| if (halfway == s) | if (halfway == s) | ||||
| return -1; | return -1; | ||||
| if (comparator.compareElements (elementToLookFor, data.elements [halfway]) >= 0) | |||||
| if (comparator.compareElements (elementToLookFor, data.elements[halfway]) >= 0) | |||||
| s = halfway; | s = halfway; | ||||
| else | else | ||||
| e = halfway; | e = halfway; | ||||
| @@ -859,7 +862,7 @@ public: | |||||
| @returns the element that has been removed | @returns the element that has been removed | ||||
| @see removeFirstMatchingValue, removeAllInstancesOf, removeRange | @see removeFirstMatchingValue, removeAllInstancesOf, removeRange | ||||
| */ | */ | ||||
| ElementType removeAndReturn (const int indexToRemove) | |||||
| ElementType removeAndReturn (int indexToRemove) | |||||
| { | { | ||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| @@ -871,7 +874,7 @@ public: | |||||
| return removed; | return removed; | ||||
| } | } | ||||
| return ElementType(); | |||||
| return {}; | |||||
| } | } | ||||
| /** Removes an element from the array. | /** Removes an element from the array. | ||||
| @@ -890,7 +893,7 @@ public: | |||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| jassert (data.elements != nullptr); | jassert (data.elements != nullptr); | ||||
| const int indexToRemove = int (elementToRemove - data.elements); | |||||
| auto indexToRemove = (int) (elementToRemove - data.elements); | |||||
| if (! isPositiveAndBelow (indexToRemove, numUsed)) | if (! isPositiveAndBelow (indexToRemove, numUsed)) | ||||
| { | { | ||||
| @@ -912,7 +915,7 @@ public: | |||||
| void removeFirstMatchingValue (ParameterType valueToRemove) | void removeFirstMatchingValue (ParameterType valueToRemove) | ||||
| { | { | ||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| ElementType* const e = data.elements; | |||||
| auto* e = data.elements.get(); | |||||
| for (int i = 0; i < numUsed; ++i) | for (int i = 0; i < numUsed; ++i) | ||||
| { | { | ||||
| @@ -969,7 +972,7 @@ public: | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| if (predicate (data.elements[i]) == true) | |||||
| if (predicate (data.elements[i])) | |||||
| { | { | ||||
| removeInternal (i); | removeInternal (i); | ||||
| ++numRemoved; | ++numRemoved; | ||||
| @@ -994,18 +997,19 @@ public: | |||||
| void removeRange (int startIndex, int numberToRemove) | void removeRange (int startIndex, int numberToRemove) | ||||
| { | { | ||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove); | |||||
| auto endIndex = jlimit (0, numUsed, startIndex + numberToRemove); | |||||
| startIndex = jlimit (0, numUsed, startIndex); | startIndex = jlimit (0, numUsed, startIndex); | ||||
| if (endIndex > startIndex) | if (endIndex > startIndex) | ||||
| { | { | ||||
| ElementType* const e = data.elements + startIndex; | |||||
| auto* e = data.elements + startIndex; | |||||
| numberToRemove = endIndex - startIndex; | numberToRemove = endIndex - startIndex; | ||||
| for (int i = 0; i < numberToRemove; ++i) | for (int i = 0; i < numberToRemove; ++i) | ||||
| e[i].~ElementType(); | e[i].~ElementType(); | ||||
| const int numToShift = numUsed - endIndex; | |||||
| auto numToShift = numUsed - endIndex; | |||||
| if (numToShift > 0) | if (numToShift > 0) | ||||
| memmove (e, e + numberToRemove, ((size_t) numToShift) * sizeof (ElementType)); | memmove (e, e + numberToRemove, ((size_t) numToShift) * sizeof (ElementType)); | ||||
| @@ -1027,7 +1031,7 @@ public: | |||||
| howManyToRemove = numUsed; | howManyToRemove = numUsed; | ||||
| for (int i = 1; i <= howManyToRemove; ++i) | for (int i = 1; i <= howManyToRemove; ++i) | ||||
| data.elements [numUsed - i].~ElementType(); | |||||
| data.elements[numUsed - i].~ElementType(); | |||||
| numUsed -= howManyToRemove; | numUsed -= howManyToRemove; | ||||
| minimiseStorageAfterRemoval(); | minimiseStorageAfterRemoval(); | ||||
| @@ -1053,7 +1057,7 @@ public: | |||||
| if (otherArray.size() > 0) | if (otherArray.size() > 0) | ||||
| { | { | ||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| if (otherArray.contains (data.elements [i])) | |||||
| if (otherArray.contains (data.elements[i])) | |||||
| removeInternal (i); | removeInternal (i); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1081,7 +1085,7 @@ public: | |||||
| else | else | ||||
| { | { | ||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| if (! otherArray.contains (data.elements [i])) | |||||
| if (! otherArray.contains (data.elements[i])) | |||||
| removeInternal (i); | removeInternal (i); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1095,16 +1099,15 @@ public: | |||||
| @param index1 index of one of the elements to swap | @param index1 index of one of the elements to swap | ||||
| @param index2 index of the other element to swap | @param index2 index of the other element to swap | ||||
| */ | */ | ||||
| void swap (const int index1, | |||||
| const int index2) | |||||
| void swap (int index1, int index2) | |||||
| { | { | ||||
| const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
| if (isPositiveAndBelow (index1, numUsed) | if (isPositiveAndBelow (index1, numUsed) | ||||
| && isPositiveAndBelow (index2, numUsed)) | && isPositiveAndBelow (index2, numUsed)) | ||||
| { | { | ||||
| std::swap (data.elements [index1], | |||||
| data.elements [index2]); | |||||
| std::swap (data.elements[index1], | |||||
| data.elements[index2]); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1122,7 +1125,7 @@ public: | |||||
| is less than zero, the value will be moved to the end | is less than zero, the value will be moved to the end | ||||
| of the array | of the array | ||||
| */ | */ | ||||
| void move (const int currentIndex, int newIndex) noexcept | |||||
| void move (int currentIndex, int newIndex) noexcept | |||||
| { | { | ||||
| if (currentIndex != newIndex) | if (currentIndex != newIndex) | ||||
| { | { | ||||
| @@ -1133,7 +1136,7 @@ public: | |||||
| if (! isPositiveAndBelow (newIndex, numUsed)) | if (! isPositiveAndBelow (newIndex, numUsed)) | ||||
| newIndex = numUsed - 1; | newIndex = numUsed - 1; | ||||
| char tempCopy [sizeof (ElementType)]; | |||||
| char tempCopy[sizeof (ElementType)]; | |||||
| memcpy (tempCopy, data.elements + currentIndex, sizeof (ElementType)); | memcpy (tempCopy, data.elements + currentIndex, sizeof (ElementType)); | ||||
| if (newIndex > currentIndex) | if (newIndex > currentIndex) | ||||
| @@ -1252,9 +1255,9 @@ private: | |||||
| void removeInternal (const int indexToRemove) | void removeInternal (const int indexToRemove) | ||||
| { | { | ||||
| --numUsed; | --numUsed; | ||||
| ElementType* const e = data.elements + indexToRemove; | |||||
| auto* e = data.elements + indexToRemove; | |||||
| e->~ElementType(); | e->~ElementType(); | ||||
| const int numberToShift = numUsed - indexToRemove; | |||||
| auto numberToShift = numUsed - indexToRemove; | |||||
| if (numberToShift > 0) | if (numberToShift > 0) | ||||
| memmove (e, e + 1, ((size_t) numberToShift) * sizeof (ElementType)); | memmove (e, e + 1, ((size_t) numberToShift) * sizeof (ElementType)); | ||||