[PATCH] D33073: [APInt] Add a utility method to change the bit width and storage size of an APInt.
Hans Wennborg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 11 08:59:33 PDT 2017
hans added inline comments.
================
Comment at: include/llvm/ADT/APInt.h:163
+ /// after this, caller takes responsibility.
+ void resize(unsigned NewBitWidth);
+
----------------
Since it's nuking the contents of the APInt, I wonder if resize() is the right name; it might confuse users who think it's similar to std::vector's resize() for example.
How about reallocate()?
================
Comment at: lib/Support/APInt.cpp:1502
if (Quotient) {
- // Set up the Quotient value's memory.
- if (Quotient->BitWidth != LHS.BitWidth) {
- if (Quotient->isSingleWord())
- Quotient->U.VAL = 0;
- else
- delete [] Quotient->U.pVal;
- Quotient->BitWidth = LHS.BitWidth;
- if (!Quotient->isSingleWord())
- Quotient->U.pVal = getClearedMemory(Quotient->getNumWords());
- } else
- Quotient->clearAllBits();
+ // Set up the Quotient value's memory and clear out any previous bits.
+ Quotient->resize(LHS.BitWidth);
----------------
A reader might interpret "clear out" as setting to zero, which resize() doesn't do right?
https://reviews.llvm.org/D33073
More information about the llvm-commits
mailing list