Modify

Opened 5 years ago

Closed 5 years ago

#6663 closed Feature Requests (fixed)

Avoiding input copying

Reported by: Olaf van der Spek <olafvdspek@…> Owned by: apolukhin
Milestone: Boost 1.52.0 Component: lexical_cast
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc:

Description

I think lexical_cast is optimized for std::string, as shown at http://www.boost.org/doc/libs/1_49_0/doc/html/boost_lexical_cast/performance.html Is it possible to take advantage of this optimization for other string types as well? For example, by providing an overload for (const char*, size_t)?

Attachments (0)

Change History (20)

comment:1 Changed 5 years ago by anonymous

Lexical cast has optimizations for almost all basic input types (char*, signed char*, unsigned char*, std::string, std::wstring, char, int, ...)
Are you just requesting an additional overload with (const char*, size_t) parameters?

comment:2 Changed 5 years ago by Olaf van der Spek <olafvdspek@…>

Yes, as the input isn't (and can't be) null-terminated.

comment:3 follow-up: Changed 5 years ago by marshall

This might be a use for string_ref, which I've been itching to get into boost.

See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3334.html

comment:4 in reply to: ↑ 3 Changed 5 years ago by apolukhin

Replying to marshall:

This might be a use for string_ref, which I've been itching to get into boost.

See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3334.html

I love the idea[[BR]] Also, I was thinking about providing optimized conversions for iterator_range<SOME_CHAR_TYPE> (described in ticket #6430). I think it would be a good solution for situations, when input chars are not NULL terminated. Such approach will be described in FAQ section of lexical_cast documentation.

comment:5 Changed 5 years ago by Olaf van der Spek <olafvdspek@…>

comment:6 Changed 5 years ago by apolukhin

  • Resolution set to fixed
  • Status changed from new to closed

(In [77517]) Fixes #6663 (much more optimizations for iterator_range, updated documentation and performance test results)

comment:7 Changed 5 years ago by olafvdspek@…

No (const char*, size_t) overload? :(

In the examples, you might want to use size() instead of length(). size() is used more often.

comment:8 Changed 5 years ago by apolukhin

Updated documentation in r77537
Still thinking about (const CharT*, size_t) overloads. Lexical_cast was initially designed to be a wrapper around stream input and output operators. However (const CharT*, size_t) overloads will add some syntax sugar and reduce compilation time (less metaprogramming can be used).

comment:9 Changed 5 years ago by olafvdspek@…

It'd still use stream input operators, right? To me, that overload is the logical base of optimizations for other overloads, like const char* and std::string.

comment:10 Changed 5 years ago by apolukhin

  • Resolution fixed deleted
  • Status changed from closed to reopened

I'll add (const CharT*, size_t) overloads after dealing with #6717. But I don't think that (const CharT*, size_t) overloads will appear in 1.50 release.

comment:11 Changed 5 years ago by apolukhin

(In [78015]) Comment out bad advise in documentation ( refs #6786, refs #6663)

comment:12 Changed 5 years ago by apolukhin

(In [78044]) Update documentation ( more info about stream character type detection + warn about new unicode types support; refs #6786, refs #6663)

comment:13 Changed 5 years ago by apolukhin

(In [78059]) Merge lexical_cast library from trunk:

  • multiple optimizations and bugfixes for boost::iterator_range (refs #6786, refs #6430, refs #6663)
  • documentation update
  • new Unicode characters support updated
  • much more tests, removed incorrect tests

comment:14 Changed 5 years ago by apolukhin

(In [80291]) Added lexical_cast(const CharType?* chars, std::size_t count) function overload (refs #6430 and refs #6663) Fixed GCC warning in numeric_cast_test.cpp

comment:15 follow-up: Changed 5 years ago by Olaf van der Spek <olafvdspek@…>

Shouldn't you use data() instead of c_str()? The terminator isn't required.

comment:16 in reply to: ↑ 15 ; follow-up: Changed 5 years ago by apolukhin

Replying to Olaf van der Spek <olafvdspek@…>:

Shouldn't you use data() instead of c_str()? The terminator isn't required.

You are right, that would be more appropriate. Just out of curiosity: modern std::basic_string implementations make a difference between data() and c_str()? (Looked through GCC sources, both calls are evaluated to _M_data(); call)

comment:17 Changed 5 years ago by apolukhin

(In [80377]) Replace .c_str() with .data() in documentation (refs #6663)

comment:18 in reply to: ↑ 16 Changed 5 years ago by Olaf van der Spek <olafvdspek@…>

Replying to apolukhin:

Just out of curiosity: modern std::basic_string implementations make a difference between data() and c_str()? (Looked through GCC sources, both calls are evaluated to _M_data(); call)

Don't know, but I doubt it.

comment:19 Changed 5 years ago by apolukhin

(In [80409]) Merge from trunk: 1) #warning replaced with #error (refs #7228) 2) Pavel Korzh added to thanks list (refs #7157) 3) BOOST_NOEXCEPT modifiers added where possible 4) better support for c++11 Unicode characters 5) fixed compilation with MSVC+STLPort 6) more agressive usage of Traits template parameter 7) Added lexical_cast(const CharType?* chars, std::size_t count) function overload (refs #6430 and refs #6663) 8) Fixed GCC warning in numeric_cast_test.cpp 9) Fix compilation of lexical cast with MSVC 2003 (refs #7255)

comment:20 Changed 5 years ago by apolukhin

  • Milestone changed from To Be Determined to Boost 1.52.0
  • Resolution set to fixed
  • Status changed from reopened to closed

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain apolukhin.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.