[clang] [clang] Make source locations space usage diagnostics numbers easier to read (PR #114999)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 5 08:22:40 PST 2024
================
@@ -2227,6 +2227,28 @@ LLVM_DUMP_METHOD void SourceManager::dump() const {
}
}
+static std::string NumberToHumanString(uint64_t Number) {
+ static constexpr std::array<std::pair<uint64_t, char>, 4> Units = {
+ {{1'000'000'000'000UL, 'T'},
+ {1'000'000'000UL, 'G'},
+ {1'000'000UL, 'M'},
+ {1'000UL, 'k'}}};
+
+ std::string HumanString;
+ llvm::raw_string_ostream HumanStringStream(HumanString);
+ for (const auto &[UnitSize, UnitSign] : Units) {
+ if (Number >= UnitSize) {
+ HumanStringStream << llvm::format(
----------------
ilya-biryukov wrote:
Suggestion: use `formatv` and it can convert to string directly.
```cpp
HumanString += llvm::formatv(...);
```
https://github.com/llvm/llvm-project/pull/114999
More information about the cfe-commits
mailing list