forked from premiere/premiere-libtorrent
more rendering fixes in client_test
This commit is contained in:
parent
cf5c9344ab
commit
e48e52770b
|
@ -186,9 +186,16 @@ std::string to_string(int v, int width)
|
|||
return s.str();
|
||||
}
|
||||
|
||||
std::string const& to_string(float v, int width, int precision = 3)
|
||||
std::string& to_string(float v, int width, int precision = 3)
|
||||
{
|
||||
static std::string ret;
|
||||
// this is a silly optimization
|
||||
// to avoid copying of strings
|
||||
enum { num_strings = 20 };
|
||||
static std::string buf[num_strings];
|
||||
static int round_robin = 0;
|
||||
std::string& ret = buf[round_robin];
|
||||
++round_robin;
|
||||
if (round_robin >= num_strings) round_robin = 0;
|
||||
ret.resize(20);
|
||||
int size = std::sprintf(&ret[0], "%*.*f", width, precision, v);
|
||||
ret.resize((std::min)(size, width));
|
||||
|
@ -229,7 +236,6 @@ std::string ratio(float a, float b)
|
|||
|
||||
std::string const& add_suffix(float val)
|
||||
{
|
||||
static std::string ret;
|
||||
const char* prefix[] = {"kB", "MB", "GB", "TB"};
|
||||
const int num_prefix = sizeof(prefix) / sizeof(const char*);
|
||||
for (int i = 0; i < num_prefix; ++i)
|
||||
|
@ -237,12 +243,12 @@ std::string const& add_suffix(float val)
|
|||
val /= 1000.f;
|
||||
if (fabs(val) < 1000.f)
|
||||
{
|
||||
ret = to_string(val, 4);
|
||||
std::string& ret = to_string(val, 4);
|
||||
ret += prefix[i];
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
ret = to_string(val, 4);
|
||||
std::string& ret = to_string(val, 4);
|
||||
ret += "PB";
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue