Skip to content

Commit f234633

Browse files
refactor(libutil): remove showBytes() in favor of renderSize()
The `showBytes()` function was redundant with `renderSize()` as the latter automatically selects the appropriate unit (KiB, MiB, GiB, etc.) based on the value, whereas `showBytes()` always formatted as MiB regardless of size. Co-authored-by: Bernardo Meurer Costa <[email protected]>
1 parent 9d4d109 commit f234633

File tree

5 files changed

+2
-11
lines changed

5 files changed

+2
-11
lines changed

src/libmain/include/nix/main/shared.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ extern volatile ::sig_atomic_t blockInt;
8989

9090
/* GC helpers. */
9191

92-
std::string showBytes(uint64_t bytes);
93-
9492
struct GCResults;
9593

9694
struct PrintFreed

src/libmain/shared.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ RunPager::~RunPager()
406406
PrintFreed::~PrintFreed()
407407
{
408408
if (show)
409-
std::cout << fmt("%d store paths deleted, %s freed\n", results.paths.size(), showBytes(results.bytesFreed));
409+
std::cout << fmt("%d store paths deleted, %s freed\n", results.paths.size(), renderSize(results.bytesFreed));
410410
}
411411

412412
} // namespace nix

src/libstore/optimise-store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void LocalStore::optimiseStore()
312312

313313
optimiseStore(stats);
314314

315-
printInfo("%s freed by hard-linking %d files", showBytes(stats.bytesFreed), stats.filesLinked);
315+
printInfo("%s freed by hard-linking %d files", renderSize(stats.bytesFreed), stats.filesLinked);
316316
}
317317

318318
void LocalStore::optimisePath(const Path & path, RepairFlag repair)

src/libutil/include/nix/util/util.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,6 @@ struct overloaded : Ts...
333333
template<class... Ts>
334334
overloaded(Ts...) -> overloaded<Ts...>;
335335

336-
std::string showBytes(uint64_t bytes);
337-
338336
/**
339337
* Provide an addition operator between strings and string_views
340338
* inexplicably omitted from the standard library.

src/libutil/util.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,4 @@ std::pair<std::string_view, std::string_view> getLine(std::string_view s)
257257
}
258258
}
259259

260-
std::string showBytes(uint64_t bytes)
261-
{
262-
return fmt("%.2f MiB", bytes / (1024.0 * 1024.0));
263-
}
264-
265260
} // namespace nix

0 commit comments

Comments
 (0)