From 481db7501ce7938ee79771acf4f4a83f548fd4d1 Mon Sep 17 00:00:00 2001 From: Fabian Giesen Date: Fri, 21 Jul 2017 20:31:58 -0700 Subject: [PATCH] stb_sprintf: Remove some gratuitous gotos --- stb_sprintf.h | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/stb_sprintf.h b/stb_sprintf.h index 1a03997..dc7992a 100644 --- a/stb_sprintf.h +++ b/stb_sprintf.h @@ -559,13 +559,9 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, cs = 0; goto scopy; #else - case 'A': // float - h = hexu; - goto hexfloat; - + case 'A': // hex float case 'a': // hex float - h = hex; - hexfloat: + h = (f[0] == 'A') ? hexu : hex; fv = va_arg(va, double); if (pr == -1) pr = 6; // default is 6 @@ -636,12 +632,8 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, goto scopy; case 'G': // float - h = hexu; - goto dosmallfloat; - case 'g': // float - h = hex; - dosmallfloat: + h = (f[0] == 'G') ? hexu : hex; fv = va_arg(va, double); if (pr == -1) pr = 6; @@ -677,12 +669,8 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, goto dofloatfromg; case 'E': // float - h = hexu; - goto doexp; - case 'e': // float - h = hex; - doexp: + h = (f[0] == 'E') ? hexu : hex; fv = va_arg(va, double); if (pr == -1) pr = 6; // default is 6 @@ -911,12 +899,8 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, #endif case 'B': // upper binary - h = hexu; - goto binary; - case 'b': // lower binary - h = hex; - binary: + h = (f[0] == 'B') ? hexu : hex; lead[0] = 0; if (fl & STBSP__LEADING_0X) { lead[0] = 2; @@ -942,13 +926,9 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, fl &= ~STBSP__LEADINGZERO; // 'p' only prints the pointer with zeros // drop through to X - case 'X': // upper binary - h = hexu; - goto dohexb; - - case 'x': // lower binary - h = hex; - dohexb: + case 'X': // upper hex + case 'x': // lower hex + h = (f[0] == 'X') ? hexu : hex; l = (4 << 4) | (4 << 8); lead[0] = 0; if (fl & STBSP__LEADING_0X) {