diff --git a/modules/beast_core/containers/beast_Array.h b/modules/beast_core/containers/beast_Array.h index 9e8e13e7f..c3f5a0c7e 100644 --- a/modules/beast_core/containers/beast_Array.h +++ b/modules/beast_core/containers/beast_Array.h @@ -723,6 +723,7 @@ public: if (isPositiveAndBelow (indexToRemove, numUsed)) { + bassert (data.elements != nullptr); ElementType removed (data.elements[indexToRemove]); removeInternal (indexToRemove); return removed; diff --git a/modules/beast_core/containers/beast_OwnedArray.h b/modules/beast_core/containers/beast_OwnedArray.h index 9ad612b86..ecbea526f 100644 --- a/modules/beast_core/containers/beast_OwnedArray.h +++ b/modules/beast_core/containers/beast_OwnedArray.h @@ -24,11 +24,6 @@ #ifndef BEAST_OWNEDARRAY_BEASTHEADER #define BEAST_OWNEDARRAY_BEASTHEADER -#include "beast_ArrayAllocationBase.h" -#include "beast_ElementComparator.h" -#include "../threads/beast_CriticalSection.h" - - //============================================================================== /** An array designed for holding objects. @@ -51,7 +46,9 @@ template -class OwnedArray : LeakChecked >, Uncopyable +class OwnedArray + : LeakChecked > + , Uncopyable { public: //============================================================================== @@ -242,23 +239,15 @@ public: as this will obviously cause deletion of dangling pointers. @param newObject the new object to add to the array - @returns the object that was added - @see set, insert, addIfNotAlreadyThere, addSorted */ - ObjectClass const& add (ObjectClass const* const newObject) noexcept + ObjectClass* add (ObjectClass* const newObject) noexcept { const ScopedLockType lock (getLock()); data.ensureAllocatedSize (numUsed + 1); bassert (data.elements != nullptr); data.elements [numUsed++] = const_cast (newObject); - return *newObject; - } - - ObjectClass& add (ObjectClass* const newObject) noexcept - { - add (const_cast (newObject)); - return *newObject; + return const_cast (newObject); } /** Inserts a new object into the array at the given index. @@ -276,12 +265,10 @@ public: @param indexToInsertAt the index at which the new element should be inserted @param newObject the new object to add to the array - @returns the object that was added - @see add, addSorted, addIfNotAlreadyThere, set */ - ObjectClass const& insert (int indexToInsertAt, - ObjectClass const* const newObject) noexcept + void insert (int indexToInsertAt, + ObjectClass* const newObject) noexcept { if (indexToInsertAt >= 0) { @@ -306,15 +293,6 @@ public: { add (newObject); } - - return *newObject; - } - - ObjectClass& insert (int indexToInsertAt, - ObjectClass* const newObject) noexcept - { - insert (indexToInsertAt, const_cast (newObject)); - return *newObject; } /** Inserts an array of values into this array at a given position. @@ -363,22 +341,13 @@ public: If the array already contains a matching object, nothing will be done. @param newObject the new object to add to the array - @returns the object */ - ObjectClass const& addIfNotAlreadyThere (ObjectClass const* const newObject) noexcept + void addIfNotAlreadyThere (const ObjectClass* const newObject) noexcept { const ScopedLockType lock (getLock()); if (! contains (newObject)) add (newObject); - - return *newObject; - } - - ObjectClass& addIfNotAlreadyThere (ObjectClass* const newObject) noexcept - { - addIfNotAlreadyThere (const_cast (newObject)); - return *newObject; } /** Replaces an object in the array with a different one. @@ -392,13 +361,11 @@ public: @param indexToChange the index whose value you want to change @param newObject the new value to set for this index. @param deleteOldElement whether to delete the object that's being replaced with the new one - @returns the object that was set - @see add, insert, remove */ - ObjectClass const& set (int const indexToChange, - ObjectClass const* const newObject, - bool const deleteOldElement = true) + void set (const int indexToChange, + const ObjectClass* const newObject, + const bool deleteOldElement = true) { if (indexToChange >= 0) { @@ -435,16 +402,6 @@ public: bassertfalse; // you're trying to set an object at a negative index, which doesn't have // any effect - but since the object is not being added, it may be leaking.. } - - return *newObject; - } - - ObjectClass& set (int const indexToChange, - ObjectClass* const newObject, - bool const deleteOldElement = true) - { - set (indexToChange, const_cast (newObject), deleteOldElement); - return *newObject; } /** Adds elements from another array to the end of this array. @@ -515,7 +472,7 @@ public: numElementsToAdd = arrayToAddFrom.size() - startIndex; data.ensureAllocatedSize (numUsed + numElementsToAdd); - bassert (numElementsToAdd <= 0 || data.elements != nullptr); + bassert (numElementsToAdd <= 0 || data.elements != nullptr); while (--numElementsToAdd >= 0) { @@ -700,8 +657,8 @@ public: const bool deleteObjects = true) { const ScopedLockType lock (getLock()); - const int endIndex = blimit (0, numUsed, startIndex + numberToRemove); - startIndex = blimit (0, numUsed, startIndex); + const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove); + startIndex = jlimit (0, numUsed, startIndex); if (endIndex > startIndex) { @@ -909,4 +866,5 @@ private: } }; -#endif // BEAST_OWNEDARRAY_BEASTHEADER + +#endif diff --git a/modules/beast_core/containers/beast_ReferenceCountedArray.h b/modules/beast_core/containers/beast_ReferenceCountedArray.h index b03559170..d768d9c55 100644 --- a/modules/beast_core/containers/beast_ReferenceCountedArray.h +++ b/modules/beast_core/containers/beast_ReferenceCountedArray.h @@ -288,7 +288,7 @@ public: @param newObject the new object to add to the array @see set, insert, addIfNotAlreadyThere, addSorted, addArray */ - void add (ObjectClass* const newObject) noexcept + ObjectClass* add (ObjectClass* const newObject) noexcept { const ScopedLockType lock (getLock()); data.ensureAllocatedSize (numUsed + 1); @@ -297,6 +297,8 @@ public: if (newObject != nullptr) newObject->incReferenceCount(); + + return newObject; } /** Inserts a new object into the array at the given index. @@ -312,8 +314,8 @@ public: @param newObject the new object to add to the array @see add, addSorted, addIfNotAlreadyThere, set */ - void insert (int indexToInsertAt, - ObjectClass* const newObject) noexcept + ObjectClass* insert (int indexToInsertAt, + ObjectClass* const newObject) noexcept { if (indexToInsertAt >= 0) { @@ -337,10 +339,12 @@ public: newObject->incReferenceCount(); ++numUsed; + + return newObject; } else { - add (newObject); + return add (newObject); } } @@ -617,8 +621,8 @@ public: { const ScopedLockType lock (getLock()); - const int start = blimit (0, numUsed, startIndex); - const int endIndex = blimit (0, numUsed, startIndex + numberToRemove); + const int start = jlimit (0, numUsed, startIndex); + const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove); if (endIndex > start) { @@ -847,11 +851,11 @@ public: /** Returns the type of scoped lock to use for locking this array */ typedef typename TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType; - private: //============================================================================== ArrayAllocationBase data; int numUsed; }; -#endif // BEAST_REFERENCECOUNTEDARRAY_BEASTHEADER + +#endif \ No newline at end of file