forked from OSchip/llvm-project
Introduce needsCleanup() for APFloat and APInt.
This is needed in clang so one can check if the object needs the destructor called after its memory was freed. This is useful when creating many APInt/APFloat objects with placement new, where the overhead of tracking the pointers for cleanup is significant. llvm-svn: 183100
This commit is contained in:
parent
17ee1abfa7
commit
d0cf5b2de3
|
@ -201,6 +201,9 @@ public:
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
/// \brief Returns whether this instance allocated memory.
|
||||||
|
bool needsCleanup() const { return partCount() > 1; }
|
||||||
|
|
||||||
/// \name Convenience "constructors"
|
/// \name Convenience "constructors"
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
|
|
@ -293,7 +293,7 @@ public:
|
||||||
|
|
||||||
/// \brief Destructor.
|
/// \brief Destructor.
|
||||||
~APInt() {
|
~APInt() {
|
||||||
if (!isSingleWord())
|
if (needsCleanup())
|
||||||
delete[] pVal;
|
delete[] pVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,6 +303,9 @@ public:
|
||||||
/// method Read).
|
/// method Read).
|
||||||
explicit APInt() : BitWidth(1) {}
|
explicit APInt() : BitWidth(1) {}
|
||||||
|
|
||||||
|
/// \brief Returns whether this instance allocated memory.
|
||||||
|
bool needsCleanup() const { return !isSingleWord(); }
|
||||||
|
|
||||||
/// Used to insert APInt objects, or objects that contain APInt objects, into
|
/// Used to insert APInt objects, or objects that contain APInt objects, into
|
||||||
/// FoldingSets.
|
/// FoldingSets.
|
||||||
void Profile(FoldingSetNodeID &id) const;
|
void Profile(FoldingSetNodeID &id) const;
|
||||||
|
|
|
@ -580,7 +580,7 @@ APFloat::initialize(const fltSemantics *ourSemantics)
|
||||||
void
|
void
|
||||||
APFloat::freeSignificand()
|
APFloat::freeSignificand()
|
||||||
{
|
{
|
||||||
if (partCount() > 1)
|
if (needsCleanup())
|
||||||
delete [] significand.parts;
|
delete [] significand.parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue