Browse Source

Fix misuse of water Arrays

tags/v2.4.1
falkTX 3 years ago
parent
commit
46a1959849
2 changed files with 22 additions and 16 deletions
  1. +17
    -5
      source/modules/water/containers/Array.h
  2. +5
    -11
      source/modules/water/containers/ArrayAllocationBase.h

+ 17
- 5
source/modules/water/containers/Array.h View File

@@ -905,19 +905,31 @@ public:
{
const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove);
startIndex = jlimit (0, numUsed, startIndex);
numberToRemove = endIndex - startIndex;
if (endIndex > startIndex)
if (numberToRemove > 0)
{
#if 1
ElementType* const e = data.elements + startIndex;
numberToRemove = endIndex - startIndex;
for (int i = 0; i < numberToRemove; ++i)
e[i].~ElementType();
const int numToShift = numUsed - endIndex;
if (numToShift > 0)
data.moveMemory (e, e + numberToRemove, numToShift);
for (int i = 0; i < numberToRemove; ++i)
e[numToShift + i].~ElementType();
#else
ElementType* dst = data.elements + startIndex;
ElementType* src = dst + numberToRemove;
const int numToShift = numUsed - endIndex;
for (int i = 0; i < numToShift; ++i)
data.moveElement (dst++, std::move (*(src++)));
for (int i = 0; i < numberToRemove; ++i)
(dst++)->~ElementType();
#endif
numUsed -= numberToRemove;
minimiseStorageAfterRemoval();
}


+ 5
- 11
source/modules/water/containers/ArrayAllocationBase.h View File

@@ -143,16 +143,14 @@ public:
size_t i = 0;
for (; i < numNewElements; ++i)
for (; i < numAllocated && i < numNewElements; ++i)
{
if (i < numAllocated)
new (newElements + i) ElementType (std::move (elements[i]));
else
new (newElements + i) ElementType ();
new (newElements + i) ElementType (std::move (elements[i]));
elements[i].~ElementType();
}
for (; i < numAllocated; ++i)
elements[i].~ElementType();
for (; i < numNewElements; ++i)
new (newElements + i) ElementType ();
elements = std::move (newElements);
}
@@ -232,8 +230,6 @@ public:
++target;
++source;
}
(--source)->~ElementType();
}
else
{
@@ -243,8 +239,6 @@ public:
--target;
--source;
}
(++source)->~ElementType();
}
}


Loading…
Cancel
Save