MCPcopy Create free account
hub / github.com/apache/trafficserver / ink_small_itoa

Function ink_small_itoa

include/tscore/ink_string.h:302–344  ·  view source on GitHub ↗

Specialized "itoa", that is optimized for small integers, and use snprintf() otherwise. On error, we'll return 0, and nothing is written to the buffer. TODO: Do these really need to be inline?

Source from the content-addressed store, hash-verified

300// On error, we'll return 0, and nothing is written to the buffer.
301// TODO: Do these really need to be inline?
302inline int
303ink_small_itoa(int val, char *buf, int buf_len)
304{
305 ink_assert(buf_len > 5);
306 ink_assert((val >= 0) && (val < 100000));
307
308 if (val < 10) { // 0 - 9
309 buf[0] = '0' + val;
310 return 1;
311 } else if (val < 100) { // 10 - 99
312 buf[1] = '0' + (val % 10);
313 val /= 10;
314 buf[0] = '0' + (val % 10);
315 return 2;
316 } else if (val < 1000) { // 100 - 999
317 buf[2] = '0' + (val % 10);
318 val /= 10;
319 buf[1] = '0' + (val % 10);
320 val /= 10;
321 buf[0] = '0' + (val % 10);
322 return 3;
323 } else if (val < 10000) { // 1000 - 9999
324 buf[3] = '0' + (val % 10);
325 val /= 10;
326 buf[2] = '0' + (val % 10);
327 val /= 10;
328 buf[1] = '0' + (val % 10);
329 val /= 10;
330 buf[0] = '0' + (val % 10);
331 return 4;
332 } else { // 10000 - 99999
333 buf[4] = '0' + (val % 10);
334 val /= 10;
335 buf[3] = '0' + (val % 10);
336 val /= 10;
337 buf[2] = '0' + (val % 10);
338 val /= 10;
339 buf[1] = '0' + (val % 10);
340 val /= 10;
341 buf[0] = '0' + (val % 10);
342 return 5;
343 }
344}
345
346inline int
347ink_fast_itoa(int32_t val, char *buf, int buf_len)

Callers 4

proxy_protocol_v1_buildFunction · 0.85
ink_fast_itoaFunction · 0.85
ink_fast_uitoaFunction · 0.85
ink_fast_ltoaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected