itoa的实现_static const char digits[200] = { ‘0‘, ‘0‘, ‘0‘, ‘

    const uint32_t a = value / 100000000; // 1 to 42
    value %= 100000000;

    if (a >= 10) {
        const unsigned i = a << 1;
        *buffer++ = cDigitsLut[i];
        *buffer++ = cDigitsLut[i + 1];
    }
    else
        *buffer++ = static_cast<char>('0' + static_cast<char>(a));

    const uint32_t b = value / 10000; // 0 to 9999
    const uint32_t c = value % 10000; // 0 to 9999

    const uint32_t d1 = (b / 100) << 1;
    const uint32_t d2 = (b % 100) << 1;

    const uint32_t d3 = (c / 100) << 1;
    const uint32_t d4 = (c % 100) << 1;

    *buffer++ = cDigitsLut[d1];
    *buffer++ = cDigitsLut[d1 + 1];
    *buffer++ = cDigitsLut[d2];
    *buffer++ = cDigitsLut[d2 + 1];
    *buffer++ = cDigitsLut[d3];
    *buffer++ = cDigitsLut[d3 + 1];
    *buffer++ = cDigitsLut[d4];
    *buffer++ = cDigitsLut[d4 + 1];
}
return buffer;

}

inline char* i32toa(int32_t value, char* buffer) {

uint32_t u = static_cast<uint32_t>(value);

if (value < 0) {

*buffer++ = '-';

u = ~u + 1;

}

return u32toa(u, buffer);

}

inline char* u64toa(uint64_t value, char* buffer) {

const char* cDigitsLut = GetDigitsLut();

const uint64_t kTen8 = 100000000;

const uint64_t kTen9 = kTen8 * 10;

const uint64_t kTen10 = kTen8 * 100;

const uint64_t kTen11 = kTen8 * 1000;

const uint64_t kTen12 = kTen8 * 10000;

const uint64_t kTen13 = kTen8 * 100000;

const uint64_t kTen14 = kTen8 * 1000000;

const uint64_t kTen15 = kTen8 * 10000000;

const uint64_t kTen16 = kTen8 * kTen8;

if (value < kTen8) {
    uint32_t v = static_cast<uint32_t>(value);
    if (v < 10000) {
        const uint32_t d1 = (v / 100) << 1;
        const uint32_t d2 = (v % 100) << 1;

        if (v >= 1000)
            *buffer++ = cDigitsLut[d1];
        if (v >= 100)
            *buffer++ = cDigitsLut[d1 + 1];
        if (v >= 10)
            *buffer++ = cDigitsLut[d2];
        *buffer++ = cDigitsLut[d2 + 1];
    }
    else {
        // value = bbbbcccc
        const uint32_t b = v / 10000;
        const uint32_t c = v % 10000;

        const uint32_t d1 = (b / 100) << 1;
        const uint32_t d2 = (b % 100) << 1;

        const uint32_t d3 = (c / 100) << 1;
        const uint32_t d4 = (c % 100) << 1;

        if (value >= 10000000)
            *buffer++ = cDigitsLut[d1];
        if (value >= 1000000)
            *buffer++ = cDigitsLut[d1 + 1];
        if (value >= 100000)
            *buffer++ = cDigitsLut[d2];
        *buffer++ = cDigitsLut[d2 + 1];

        *buffer++ = cDigitsLut[d3];
        *buffer++ = cDigitsLut[d3 + 1];
        *buffer++ = cDigitsLut[d4];
        *buffer++ = cDigitsLut[d4 + 1];
    }
}
else if (value < kTen16) {
    const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
    const uint32_t v1 = static_cast<uint32_t>(value % kTen8);

    const uint32_t b0 = v0 / 10000;
    const uint32_t c0 = v0 % 10000;

    const uint32_t d1 = (b0 / 100) << 1;
    const uint32_t d2 = (b0 % 100) << 1;

    const uint32_t d3 = (c0 / 100) << 1;
    const uint32_t d4 = (c0 % 100) << 1;

    const uint32_t b1 = v1 / 10000;
    const uint32_t c1 = v1 % 10000;

    const uint32_t d5 = (b1 / 100) << 1;
    const uint32_t d6 = (b1 % 100) << 1;

    const uint32_t d7 = (c1 / 100) << 1;
    const uint32_t d8 = (c1 % 100) << 1;

    if (value >= kTen15)
        *buffer++ = cDigitsLut[d1];
    if (value >= kTen14)
        *buffer++ = cDigitsLut[d1 + 1];
    if (value >= kTen13)
        *buffer++ = cDigitsLut[d2];
    if (value >= kTen12)
        *buffer++ = cDigitsLut[d2 + 1];
    if (value >= kTen11)
        *buffer++ = cDigitsLut[d3];
    if (value >= kTen10)
        *buffer++ = cDigitsLut[d3 + 1];
    if (value >= kTen9)
        *buffer++ = cDigitsLut[d4];
    if (value >= kTen8)
        *buffer++ = cDigitsLut[d4 + 1];

    *buffer++ = cDigitsLut[d5];
    *buffer++ = cDigitsLut[d5 + 1];
    *buffer++ = cDigitsLut[d6];
    *buffer++ = cDigitsLut[d6 + 1];
    *buffer++ = cDigitsLut[d7];
    *buffer++ = cDigitsLut[d7 + 1];
    *buffer++ = cDigitsLut[d8];
    *buffer++ = cDigitsLut[d8 + 1];
}
else {
    const uint32_t a = static_cast<uint32_t>(value / kTen16); // 1 to 1844
    value %= kTen16;

    if (a < 10)
        *buffer++ = static_cast<char>('0' + static_cast<char>(a));
    else if (a < 100) {
        const uint32_t i = a << 1;
        *buffer++ = cDigitsLut[i];
        *buffer++ = cDigitsLut[i + 1];
    }
    else if (a < 1000) {
        *buffer++ = static_cast<char>('0' + static_cast<char>(a / 100));

        const uint32_t i = (a % 100) << 1;
        *buffer++ = cDigitsLut[i];
        *buffer++ = cDigitsLut[i + 1];
    }
    else {
        const uint32_t i = (a / 100) << 1;
        const uint32_t j = (a % 100) << 1;
        *buffer++ = cDigitsLut[i];
        *buffer++ = cDigitsLut[i + 1];
        *buffer++ = cDigitsLut[j];
        *buffer++ = cDigitsLut[j + 1];
    }

    const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
    const uint32_t v1 = static_cast<uint32_t>(value % kTen8);

    const uint32_t b0 = v0 / 10000;
    const uint32_t c0 = v0 % 10000;

    const uint32_t d1 = (b0 / 100) << 1;
    const uint32_t d2 = (b0 % 100) << 1;

    const uint32_t d3 = (c0 / 100) << 1;
    const uint32_t d4 = (c0 % 100) << 1;

    const uint32_t b1 = v1 / 10000;
    const uint32_t c1 = v1 % 10000;

    const uint32_t d5 = (b1 / 100) << 1;
    const uint32_t d6 = (b1 % 100) << 1;

    const uint32_t d7 = (c1 / 100) << 1;
    const uint32_t d8 = (c1 % 100) << 1;

    *buffer++ = cDigitsLut[d1];
    *buffer++ = cDigitsLut[d1 + 1];
    *buffer++ = cDigitsLut[d2];
    *buffer++ = cDigitsLut[d2 + 1];
    *buffer++ = cDigitsLut[d3];
    *buffer++ = cDigitsLut[d3 + 1];
    *buffer++ = cDigitsLut[d4];
    *buffer++ = cDigitsLut[d4 + 1];
    *buffer++ = cDigitsLut[d5];
    *buffer++ = cDigitsLut[d5 + 1];
    *buffer++ = cDigitsLut[d6];
    *buffer++ = cDigitsLut[d6 + 1];
    *buffer++ = cDigitsLut[d7];
    *buffer++ = cDigitsLut[d7 + 1];
    *buffer++ = cDigitsLut[d8];
    *buffer++ = cDigitsLut[d8 + 1];
}

return buffer;
相关推荐
hackeroink1 小时前
【2024版】最新推荐好用的XSS漏洞扫描利用工具_xss扫描工具
前端·xss
迷雾漫步者3 小时前
Flutter组件————FloatingActionButton
前端·flutter·dart
向前看-3 小时前
验证码机制
前端·后端
xlsw_3 小时前
java全栈day20--Web后端实战(Mybatis基础2)
java·开发语言·mybatis
神仙别闹4 小时前
基于java的改良版超级玛丽小游戏
java
燃先生._.4 小时前
Day-03 Vue(生命周期、生命周期钩子八个函数、工程化开发和脚手架、组件化开发、根组件、局部注册和全局注册的步骤)
前端·javascript·vue.js
远游客07134 小时前
centos stream 8下载安装遇到的坑
linux·服务器·centos
黄油饼卷咖喱鸡就味增汤拌孜然羊肉炒饭4 小时前
SpringBoot如何实现缓存预热?
java·spring boot·spring·缓存·程序员
暮湫5 小时前
泛型(2)
java