Opened 11 years ago

Closed 10 years ago

#6663 closed Feature Requests (fixed)

Avoiding input copying

Reported by: Olaf van der Spek <olafvdspek@…> Owned by: Antony Polukhin
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)?

Change History (20)

comment:1 by anonymous, 11 years ago

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 by Olaf van der Spek <olafvdspek@…>, 11 years ago

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

comment:3 by Marshall Clow, 11 years ago

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

in reply to:  3 comment:4 by Antony Polukhin, 11 years ago

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 by Olaf van der Spek <olafvdspek@…>, 11 years ago

comment:6 by Antony Polukhin, 11 years ago

Resolution: fixed
Status: newclosed

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

comment:7 by olafvdspek@…, 11 years ago

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 by Antony Polukhin, 11 years ago

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 by olafvdspek@…, 11 years ago

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 by Antony Polukhin, 11 years ago

Resolution: fixed
Status: closedreopened

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 by Antony Polukhin, 11 years ago

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

comment:12 by Antony Polukhin, 11 years ago

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

comment:13 by Antony Polukhin, 11 years ago

(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 by Antony Polukhin, 10 years ago

(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 by Olaf van der Spek <olafvdspek@…>, 10 years ago

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

in reply to:  15 ; comment:16 by Antony Polukhin, 10 years ago

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 by Antony Polukhin, 10 years ago

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

in reply to:  16 comment:18 by Olaf van der Spek <olafvdspek@…>, 10 years ago

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 by Antony Polukhin, 10 years ago

(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 by Antony Polukhin, 10 years ago

Milestone: To Be DeterminedBoost 1.52.0
Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.