Suggestion of fixing folly::to<std::string>(double/float) performance issue
authorBi Xue <bixue@fb.com>
Sun, 21 Aug 2016 04:10:36 +0000 (21:10 -0700)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Sun, 21 Aug 2016 04:23:26 +0000 (21:23 -0700)
commit10ed79f7b20aeb03e720cd9a01f43f5a5f15f021
tree3c3aa1d33cc34f4c5eee63a9db97ff0d4d67b744
parent3c2fad7c4e858b8bfa4018c4524a2af1a2c8156f
Suggestion of fixing folly::to<std::string>(double/float) performance issue

Summary:
When calling folly::to<SomeString>(double), generic implementation will
firstly reserve 24 (or 25 when negative value) bytes. This will introduce
a malloc call for most of mainstream string implementation.

But for most cases, a floating point doesn't need 24 (or 25) bytes to
be converted as a string.

This diff try to introduce a special version which does not do string reserve.

Reviewed By: ericniebler

Differential Revision: D3728171

fbshipit-source-id: d70ead396ad6c8d0df1f542c5516f7534e82cb97
folly/Conv.h