Boost logo

Boost :

Subject: [boost] [lexical cast] Performance improvements
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2011-03-19 16:44:58

Working with Boost Lexical Cast library found that some casts are
working really slow.
For example, cast from short to int is done via cast from short to char[],
and cast from char[] to int.
Cast from char* to string is done via string() constructor call and string`s
append function call (instead of string constructor call with char array as a

So I wrote patch to Boost Lexical Cast library, that returns Target directly
constructed from Source in cases, when:
1) Source and Target are arithmetics (and not char or wchar_t), and
all values of
Source are in range of Target
2) Source and Target are both char or both wchar_t
3) Source is array of CharT and Target is std::basic_string<CharT, ...>
4) Source and Target are std::basic_string with same template parameters

It gives performance boost more than 10 times in case 1) , about 7
times in case 2),
and about 1.5 times in cases 3) and 4).

Existing tests for Boost Lexical Cast library cover considered cases.
Patch was successfully tested on Intel 11.1.072, g++-4.4.5, VC++9 compilers.

P.S.: I`m a newbie here, so where shall I send this patch? Shall I
test it on other

Boost list run by bdawes at, gregod at, cpdaniel at, john at