================
@@ -2278,8 +2285,28 @@ void APInt::toString(SmallVectorImpl<char> &Str, 
unsigned Radix, bool Signed,
     }
   } else {
     int Pos = 0;
+    // The value of cutOffSize is not special, it is just a number of
+    // characters that gives us enough info without losing readability.
+    constexpr int cutOffSize = 20;
     while (Tmp.getBoolValue()) {
       uint64_t Digit;
+      if (truncate && Pos == cutOffSize) {
+        unsigned numDigits = (int32_t)(Tmp.logBase2()/log2(Radix))+1;
----------------
erichkeane wrote:

```suggestion
        unsigned numDigits = 
static_cast<int32_t>(Tmp.logBase2()/log2(Radix))+1);
```

ALSO: Why cast to int32, but then assign to an unsigned?  Should we be doing 
math as unsigned?  or as signed?

Also, a comment on what this is doing could be helpful.

Also... is there value to pre-calculating `log2(Radix)` and keeping it 
somewhere so we don't re-evaluate it every time?  or is `log2` `pure`?

https://github.com/llvm/llvm-project/pull/145053
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to