X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b58e2c7c56b1416a343e81f9f80cb1f02c128e25..5404685b66b92f93da7ded5f8fe44fbabea38ba4:/apt-pkg/install-progress.cc diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc index c77c240c3..be5b8b5c7 100644 --- a/apt-pkg/install-progress.cc +++ b/apt-pkg/install-progress.cc @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -321,19 +322,14 @@ std::string PackageManagerFancy::GetTextProgressStr(float Percent, int OutputSize) { std::string output; - int i; - - // should we raise a exception here instead? - if (Percent < 0.0 || Percent > 1.0 || OutputSize < 3) + if (unlikely(OutputSize < 3)) return output; - - int BarSize = OutputSize - 2; // bar without the leading "[" and trailing "]" - output += "["; - for(i=0; i < BarSize*Percent; i++) - output += "#"; - for (/*nothing*/; i < BarSize; i++) - output += "."; - output += "]"; + + int const BarSize = OutputSize - 2; // bar without the leading "[" and trailing "]" + int const BarDone = std::max(0, std::min(BarSize, static_cast(std::floor(Percent * BarSize)))); + output.append("["); + std::fill_n(std::fill_n(std::back_inserter(output), BarDone, '#'), BarSize - BarDone, '.'); + output.append("]"); return output; }