diff options
author | Keith Bostic <keith.bostic@mongodb.com> | 2016-09-27 20:46:48 -0400 |
---|---|---|
committer | Alex Gorrod <alexander.gorrod@mongodb.com> | 2016-09-28 10:46:48 +1000 |
commit | 50bfdbcdcf807325be2f82ec041d2c36c8eeeea3 (patch) | |
tree | c6372941267ac6a08c333d5c71994d22e2807e2e /test | |
parent | 5afcee5924826184fe22b7554d2af6ed04029609 (diff) | |
download | mongo-50bfdbcdcf807325be2f82ec041d2c36c8eeeea3.tar.gz |
WT-2858 Rename wtperf's CONFIG structure (#3065)
Also replace key-string generation implementation with a more efficient implementation.
Diffstat (limited to 'test')
-rw-r--r-- | test/utility/test_util.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/utility/test_util.h b/test/utility/test_util.h index 3c1d0e2630a..1047d1ca8a0 100644 --- a/test/utility/test_util.h +++ b/test/utility/test_util.h @@ -108,6 +108,62 @@ typedef struct { __func__, __LINE__, #call, __VA_ARGS__); \ } while (0) +/* + * u64_to_string -- + * Convert a uint64_t to a text string. + * + * Algorithm from Andrei Alexandrescu's talk: "Three Optimization Tips for C++" + */ +static inline void +u64_to_string(uint64_t n, char **pp) +{ + static const char hundred_lookup[201] = + "0001020304050607080910111213141516171819" + "2021222324252627282930313233343536373839" + "4041424344454647484950515253545556575859" + "6061626364656667686970717273747576777879" + "8081828384858687888990919293949596979899"; + u_int i; + char *p; + + /* + * The argument pointer references the last element of a buffer (which + * must be large enough to hold any possible value). + * + * Nul-terminate the buffer. + */ + for (p = *pp, *p-- = '\0'; n >= 100; n /= 100) { + i = (n % 100) * 2; + *p-- = hundred_lookup[i + 1]; + *p-- = hundred_lookup[i]; + } + + /* Handle the last two digits. */ + i = (u_int)n * 2; + *p = hundred_lookup[i + 1]; + if (n >= 10) + *--p = hundred_lookup[i]; + + /* Return a pointer to the first byte of the text string. */ + *pp = p; +} + +/* + * u64_to_string_zf -- + * Convert a uint64_t to a text string, zero-filling the buffer. + */ +static inline void +u64_to_string_zf(uint64_t n, char *buf, size_t len) +{ + char *p; + + p = buf + (len - 1); + u64_to_string(n, &p); + + while (p > buf) + *--p = '0'; +} + /* Allow tests to add their own death handling. */ extern void (*custom_die)(void); |