MCPcopy Create free account
hub / github.com/apache/brpc / AppendDecimal

Function AppendDecimal

src/brpc/redis_command.cpp:37–47  ·  view source on GitHub ↗

Much faster than snprintf(..., "%lu", d);

Source from the content-addressed store, hash-verified

35
36// Much faster than snprintf(..., "%lu", d);
37inline size_t AppendDecimal(char* outbuf, unsigned long d) {
38 char buf[24]; // enough for decimal 64-bit integers
39 size_t n = sizeof(buf);
40 do {
41 const unsigned long q = d / 10;
42 buf[--n] = d - q * 10 + '0';
43 d = q;
44 } while (d);
45 fast_memcpy(outbuf, buf + n, sizeof(buf) - n);
46 return sizeof(buf) - n;
47}
48
49// This function is the hotspot of RedisCommandFormatV() when format is
50// short or does not have many %. In a 100K-time call to formating of

Callers 1

AppendHeaderFunction · 0.85

Calls 1

fast_memcpyFunction · 0.85

Tested by

no test coverage detected