Modify

Opened 6 years ago

Closed 6 years ago

#5564 closed Patches (fixed)

lexical_cast performance boost for signed and unsigned char types

Reported by: Bolotov Ilya, Mishakov Daniil <daniil987@…> Owned by: Antony Polukhin
Milestone: To Be Determined Component: lexical_cast
Version: Boost Development Trunk Severity: Optimization
Keywords: Cc:

Description

We were looking through the sources of boost::lexical_cast library, and found a possible way of optimization.

According to the [27.6.2.5.4 Character inserter function templates] of Programming languages - C++ standard, basic_ostream::operator<< reinterpret_casts unsigned char* and signed char* to char* and calls operator<<. So we can convert from unsigned char* and signed char* types to char* type and use optimized boost::lexical_cast coversion methods without construction of basic_streambuf<CharT> objects. Same approach can be used with signed char and unsigned char (we can just static_cast them to char type).

According to the [27.6.1.2.3 basic_istream::operator>>] of Programming languages - C++ standard, basic_istream::operator>> for unsigned chars and signed chars behaves the same way, as for char type. boost::lexical_cast library treats remained in stream data as an error, so when the sizeof(CharT) is bigger than sizeof(char), the there will remain some data in stream and such situation can be interpreted as error. We can detect such cases at compile time, using BOOST_STATIC_ASSERT( sizeof(CharT) == sizeof(signed char) );

Using those optimizations, we won't construct basic_streambuf<CharT> object, so there will be no dynamic memory allocation and we will use the lexical_cast algorithms optimized for char and char* types.

Patch contains the required modifications and was tested on gcc4.5

Attachments (1)

lexical_cast.diff (4.7 KB) - added by Bolotov Ilya, Mishakov Daniil <daniil987@…> 6 years ago.
Patch for the trunk version

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by Bolotov Ilya, Mishakov Daniil <daniil987@…>

Attachment: lexical_cast.diff added

Patch for the trunk version

comment:1 Changed 6 years ago by Antony Polukhin

Status: newassigned

comment:2 Changed 6 years ago by Antony Polukhin

Resolution: fixed
Status: assignedclosed

(In [72203]) Fixes #5564. Adds tests on #5564 and more tests on #5557

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Antony Polukhin.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.