简体   繁体   English

为什么 GCC 使用 std::vsnprintf 实现 std::to_string?

[英]Why does GCC implement std::to_string using std::vsnprintf?

Recently, I looked into GCC's basic_string.h and noticed that all std::to_string overloads are implemented using std::vsnprintf like for example:最近,我查看了 GCC 的basic_string.h并注意到所有std::to_string重载都是使用std::vsnprintf实现的,例如:

inline string
to_string(int __val)
{
    return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int), "%d", __val);
}

Wouldn't this introduce a lot of overhead?这不会引入很多开销吗? Stringifying an integer base 10 is possible in just a few lines of code, so why would this be implemented using vsnprintf ?只需几行代码就可以将 integer 以 10 为基数进行字符串化,那么为什么要使用vsnprintf来实现呢?

This looked good enough considering they had lots of other stuff to implement for C++ 11.考虑到他们有很多其他的东西要为 C++ 11 实现,这看起来已经足够好了。

They optimized it recently with gcc 10 release.他们最近使用 gcc 10 版本对其进行了优化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM