mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 19:40:18 -07:00
- Code optimization
This commit is contained in:
parent
4c6d6a35f3
commit
8565f1e61e
1 changed files with 6 additions and 10 deletions
16
src/misc.h
16
src/misc.h
|
@ -106,17 +106,13 @@ class misc : public QObject{
|
||||||
// see http://en.wikipedia.org/wiki/Kilobyte
|
// see http://en.wikipedia.org/wiki/Kilobyte
|
||||||
// value must be given in bytes
|
// value must be given in bytes
|
||||||
static QString friendlyUnit(float val) {
|
static QString friendlyUnit(float val) {
|
||||||
if(val < 0) {
|
if(val < 0)
|
||||||
return tr("Unknown", "Unknown (size)");
|
return tr("Unknown", "Unknown (size)");
|
||||||
}
|
const QString units[5] = {tr("B", "bytes"), tr("KiB", "kibibytes (1024 bytes)"), tr("MiB", "mebibytes (1024 kibibytes)"), tr("GiB", "gibibytes (1024 mibibytes)"), tr("TiB", "tebibytes (1024 gibibytes)")};
|
||||||
const QString units[4] = {tr("B", "bytes"), tr("KiB", "kibibytes (1024 bytes)"), tr("MiB", "mebibytes (1024 kibibytes)"), tr("GiB", "gibibytes (1024 mibibytes)")};
|
char i = 0;
|
||||||
for(unsigned int i=0; i<5; ++i) {
|
while(val > 1024. && i++<6)
|
||||||
if (val < 1024.) {
|
val /= 1024.;
|
||||||
return QString(QByteArray::number(val, 'f', 1)) + units[i];
|
return QString(QByteArray::number(val, 'f', 1)) + units[(int)i];
|
||||||
}
|
|
||||||
val /= 1024.;
|
|
||||||
}
|
|
||||||
return QString(QByteArray::number(val, 'f', 1)) + tr("TiB", "tebibytes (1024 gibibytes)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isPreviewable(QString extension){
|
static bool isPreviewable(QString extension){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue