aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2018-11-04 12:57:49 +0100
committerMarco Paland <marco@paland.com>2018-11-04 12:57:49 +0100
commitcdba96d82c0ed3a20a8239f94e3e7f57560ff2a2 (patch)
tree06a81ec42a5f2282c5b334c07cc3569d7bcefd66
parent735abbca130bb7180f762ff4859302bef8212383 (diff)
downloadprintf-cdba96d82c0ed3a20a8239f94e3e7f57560ff2a2.tar.gz
printf-cdba96d82c0ed3a20a8239f94e3e7f57560ff2a2.tar.bz2
printf-cdba96d82c0ed3a20a8239f94e3e7f57560ff2a2.zip
perf(printf): check flags outside while loop
-rw-r--r--printf.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/printf.c b/printf.c
index b5a38fc..8cbb211 100644
--- a/printf.c
+++ b/printf.c
@@ -166,11 +166,13 @@ static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t ma
const size_t start_idx = idx;
// pad leading zeros
- while (!(flags & FLAGS_LEFT) && (len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
- buf[len++] = '0';
- }
- while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
- buf[len++] = '0';
+ if (!(flags & FLAGS_LEFT)) {
+ while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
+ buf[len++] = '0';
+ }
+ while ((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
+ buf[len++] = '0';
+ }
}
// handle hash
@@ -381,8 +383,10 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
}
// pad leading zeros
- while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
- buf[len++] = '0';
+ if (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) {
+ while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
+ buf[len++] = '0';
+ }
}
// handle sign