[Boost-bugs] [Boost C++ Libraries] #5564: lexical_cast performance boost for signed and unsigned char types

Subject: [Boost-bugs] [Boost C++ Libraries] #5564: lexical_cast performance boost for signed and unsigned char types
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-05-25 09:48:41


#5564: lexical_cast performance boost for signed and unsigned char types
-----------------------------------------------------------------+----------
 Reporter: Bolotov Ilya, Mishakov Daniil <daniil987@…> | Owner: apolukhin
     Type: Patches | Status: new
Milestone: To Be Determined | Component: lexical_cast
  Version: Boost Development Trunk | Severity: Optimization
 Keywords: |
-----------------------------------------------------------------+----------
 We were looking through the sources of boost::lexical_cast library, and
 found a possible way of optimization.[[BR]]

 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).[[BR]]

 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) );[[BR]]

 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.[[BR]]

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

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5564>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC