From 0b5e329a8ba2461ccb7017d3adfc972f9dccd830 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Dec 2017 21:51:52 +0100 Subject: deal with floats without old-style cast We have no speed problem with handling floats/doubles in our progress handling, but that shouldn't prevent us from cleaning up the handling slightly to avoid unclean casting to ints. Reported-By: gcc -Wdouble-promotion -Wold-style-cast --- apt-pkg/acquire.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 408cf6df5..f6e323d30 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -437,7 +438,7 @@ string pkgAcquire::QueueName(string Uri,MethodConfig const *&Config) clog << "Found " << Instances << " instances of " << U.Access << endl; } - if (Instances >= (unsigned int)_config->FindI("Acquire::QueueHost::Limit",10)) + if (Instances >= static_cast(_config->FindI("Acquire::QueueHost::Limit",10))) return U.Access; return FullQueueName; @@ -1074,7 +1075,7 @@ bool pkgAcquire::Queue::Cycle() // Look for a queable item QItem *I = Items; int ActivePriority = 0; - while (PipeDepth < (signed)MaxPipeDepth) + while (PipeDepth < static_cast(MaxPipeDepth)) { for (; I != 0; I = I->Next) { if (I->Owner->Status == pkgAcquire::Item::StatFetching) @@ -1285,7 +1286,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) else CurrentCPS = ((CurrentBytes - ResumeSize) - LastBytes)/Delta; LastBytes = CurrentBytes - ResumeSize; - ElapsedTime = (unsigned long long)Delta; + ElapsedTime = std::llround(Delta); Time = NewTime; } @@ -1295,8 +1296,8 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) Percent = 0; else // use both files and bytes because bytes can be unreliable - Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) + - 0.2 * (CurrentItems/float(TotalItems)*100.0)); + Percent = (0.8 * (CurrentBytes/double(TotalBytes)*100.0) + + 0.2 * (CurrentItems/double(TotalItems)*100.0)); // debug if (_config->FindB("Debug::acquire::progress", false) == true) @@ -1380,7 +1381,7 @@ void pkgAcquireStatus::Stop() else CurrentCPS = FetchedBytes/Delta; LastBytes = CurrentBytes; - ElapsedTime = (unsigned long long)Delta; + ElapsedTime = std::llround(Delta); } /*}}}*/ // AcquireStatus::Fetched - Called when a byte set has been fetched /*{{{*/ -- cgit v1.2.3