Modify

Ticket #6663 (closed Feature Requests: fixed)

Opened 2 years ago

Last modified 20 months ago

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

Change History

comment:1 Changed 2 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 2 years ago by Olaf van der Spek <olafvdspek@…>

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

comment:3 follow-up: ↓ 4 Changed 2 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 2 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 2 years ago by Olaf van der Spek <olafvdspek@…>

comment:6 Changed 2 years ago by apolukhin

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

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

comment:7 Changed 2 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 2 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 2 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 2 years ago by apolukhin

  • Status changed from closed to reopened
  • Resolution fixed deleted

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 2 years ago by apolukhin

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

comment:12 Changed 2 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 2 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 20 months 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: ↓ 16 Changed 20 months 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: ↓ 18 Changed 20 months 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 20 months ago by apolukhin

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

comment:18 in reply to: ↑ 16 Changed 20 months 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 20 months 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 20 months ago by apolukhin

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

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
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.