Browse Source

Removed unnecessary memory allocation when assigning a big integer with the same memory requirements

tags/2021-05-28
hogliux 9 years ago
parent
commit
13c501da0c
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      modules/juce_core/maths/juce_BigInteger.cpp

+ 6
- 4
modules/juce_core/maths/juce_BigInteger.cpp View File

@@ -158,12 +158,14 @@ BigInteger& BigInteger::operator= (const BigInteger& other)
if (this != &other) if (this != &other)
{ {
highestBit = other.getHighestBit(); highestBit = other.getHighestBit();
allocatedSize = (size_t) jmax ((size_t) numPreallocatedInts, sizeNeededToHold (highestBit));
const size_t newAllocatedSize = (size_t) jmax ((size_t) numPreallocatedInts, sizeNeededToHold (highestBit));
if (allocatedSize <= numPreallocatedInts)
if (newAllocatedSize <= numPreallocatedInts)
heapAllocation.free(); heapAllocation.free();
else
heapAllocation.malloc (allocatedSize);
else if (newAllocatedSize != allocatedSize)
heapAllocation.malloc (newAllocatedSize);
allocatedSize = newAllocatedSize;
memcpy (getValues(), other.getValues(), sizeof (uint32) * allocatedSize); memcpy (getValues(), other.getValues(), sizeof (uint32) * allocatedSize);
negative = other.negative; negative = other.negative;


Loading…
Cancel
Save