From ef0186ae4b97c8940e77e8600cbaa06eeb3f8bdd Mon Sep 17 00:00:00 2001 From: ellson Date: Fri, 21 Dec 2007 02:03:05 +0000 Subject: [PATCH] minor optimzation, use unterminated string, permissible now that gvprintnum is private. --- lib/gvc/gvdevice.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index 2a39d97e0..fd44b2b34 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -117,6 +117,9 @@ void gvdevice_printf(GVJ_t * job, const char *format, ...) #define val_str(n, x) static double n = x; static unsigned char n##str[] = #x; val_str(maxnegnum, -999999999999999.99) +/* we use len and don't need the string to be terminated */ +/* #define TERMINATED_NUMBER_STRING */ + /* Note. Returned string is only good until the next call to gvprintnum */ static unsigned char * gvprintnum (int *len, double number) { @@ -153,7 +156,9 @@ static unsigned char * gvprintnum (int *len, double number) } if ((negative = (N < 0))) /* avoid "-0" by testing rounded int */ N = -N; /* make number +ve */ +#ifdef TERMINATED_NUMBER_STRING *--result = '\0'; /* terminate the result string */ +#endif showzeros = false; /* don't print trailing zeros */ for (i = DECPLACES; N || i > 0; i--) { /* non zero remainder, or still in fractional part */ @@ -172,7 +177,11 @@ static unsigned char * gvprintnum (int *len, double number) } if (negative) /* print "-" if needed */ *--result = '-'; +#ifdef TERMINATED_NUMBER_STRING *len = tmpbuf+sizeof(maxnegnumstr)-1 - result; +#else + *len = tmpbuf+sizeof(maxnegnumstr) - result; +#endif return result; } -- 2.50.1