From 59b9b316044b165782ae7295eebe4626be1f5507 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 4 Jul 2024 06:39:18 +0300 Subject: [PATCH] public: avoid useless copies in Q_pretifymem --- public/crtlib.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/public/crtlib.c b/public/crtlib.c index 09a07788..5ecdc49f 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -410,9 +410,9 @@ char *Q_pretifymem( float value, int digitsafterdecimal ) { static char output[8][32]; static int current; - float onekb = 1024.0f; - float onemb = onekb * onekb; - char suffix[8]; + const float onekb = 1024.0f; + const float onemb = onekb * onekb; + const char *suffix; char *out = output[current]; char val[32], *i, *o, *dot; int pos; @@ -423,14 +423,17 @@ char *Q_pretifymem( float value, int digitsafterdecimal ) if( value > onemb ) { value /= onemb; - Q_strncpy( suffix, " Mb", sizeof( suffix )); + suffix = " Mb"; } else if( value > onekb ) { value /= onekb; - Q_strncpy( suffix, " Kb", sizeof( suffix )); + suffix = " Kb"; + } + else + { + suffix = " bytes"; } - else Q_strncpy( suffix, " bytes", sizeof( suffix )); // clamp to >= 0 digitsafterdecimal = Q_max( digitsafterdecimal, 0 );