Author: sebor
Date: Thu Feb 16 13:23:46 2006
New Revision: 378371
URL: http://svn.apache.org/viewcvs?rev=378371&view=rev
Log:
2006-02-16 Martin Sebor <[EMAIL PROTECTED]>
STDCXX-146
* sstream (stringbuf, istringstream, ostringstream, stringstream):
Added ctor and str() overloads for const char_type* for improved
efficiency (gives a 20% speedup).
(_RWSTD_NO_EXT_STRINGBUF_STR): New macro guarding the extended
str() overloads.
(stringbuf dtor, underflow): Outlined virtual functions.
* sstream.cc (stringuf ctor, str): Implemented in terms
of the new str(const char_type*) overload for simplicity.
Modified:
incubator/stdcxx/trunk/include/sstream
incubator/stdcxx/trunk/include/sstream.cc
Modified: incubator/stdcxx/trunk/include/sstream
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/include/sstream?rev=378371&r1=378370&r2=378371&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/sstream (original)
+++ incubator/stdcxx/trunk/include/sstream Thu Feb 16 13:23:46 2006
@@ -3,7 +3,7 @@
*
* sstream - Declarations for the Standard Library basic streams
*
- * $Id: //stdlib/dev/include/sstream#32 $
+ * $Id$
*
***************************************************************************
*
@@ -115,17 +115,35 @@
}
_EXPLICIT
- basic_stringbuf (const _C_string_type &__str,
+ basic_stringbuf (const _C_string_type&,
ios_base::openmode = _RW::__rw_in_out);
+ // extension
+ _EXPLICIT
+ basic_stringbuf (const char_type*,
+ ios_base::openmode = _RW::__rw_in_out);
+
virtual ~basic_stringbuf ();
_C_string_type str () const {
return _C_strlen () == 0 ? _C_string_type ()
: _C_string_type (this->_C_buffer, _C_strlen ());
}
-
- void str (const _C_string_type&);
+
+#ifdef _RWSTD_NO_EXT_STRINGBUF_STR
+
+private:
+
+#endif // _RWSTD_NO_EXT_STRINGBUF_STR
+
+ // extension
+ void str (const char_type*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
+
+public:
+
+ void str (const _C_string_type &__str) {
+ str (__str.data (), __str.size ());
+ }
protected:
@@ -163,33 +181,6 @@
template <class _CharT, class _Traits, class _Allocator>
-inline basic_stringbuf<_CharT, _Traits, _Allocator>::~basic_stringbuf ()
-{
- typedef _RWSTD_ALLOC_TYPE (allocator_type, char_type) _ValueAlloc;
-
- if (this->_C_own_buf ())
- _ValueAlloc ().deallocate (this->_C_buffer, this->_C_bufsize);
-}
-
-
-template <class _CharT, class _Traits, class _Allocator>
-inline _TYPENAME basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
-basic_stringbuf<_CharT, _Traits, _Allocator>::underflow ()
-{
- _RWSTD_ASSERT (this->_C_is_valid ());
-
- if (this->gptr () < this->egptr ()) {
-
- _RWSTD_ASSERT (0 != this->gptr ());
-
- return traits_type::to_int_type (*this->gptr ());
- }
-
- return traits_type::eof ();
-}
-
-
-template <class _CharT, class _Traits, class _Allocator>
inline _RWSTD_STREAMSIZE
basic_stringbuf<_CharT, _Traits, _Allocator>::
_C_grow (_RWSTD_STREAMSIZE __from, _RWSTD_STREAMSIZE __to) const
@@ -226,6 +217,13 @@
: basic_istream<char_type, traits_type>(rdbuf ()),
_C_sb (__str, __mode | ios_base::in) { }
+ // extension
+ _EXPLICIT
+ basic_istringstream (const char_type * __s,
+ ios_base::openmode __mode = ios_base::in)
+ : basic_istream<char_type, traits_type>(rdbuf ()),
+ _C_sb (__s, __mode | ios_base::in) { }
+
basic_stringbuf<char_type, traits_type, allocator_type> *rdbuf () const {
// necessary to help SunPro 5.0/T9
typedef basic_istringstream <char_type, traits_type, allocator_type>
@@ -237,7 +235,16 @@
return rdbuf ()->str ();
}
- void str (const _C_string_type& __str) {
+#ifdef _RWSTD_NO_EXT_STRINGBUF_STR
+
+ // extension
+ void str (const char_type *__s, _RWSTD_SIZE_T __len = _RWSTD_SIZE_MAX) {
+ rdbuf ()->str (__s, __len);
+ }
+
+#endif // _RWSTD_NO_EXT_STRINGBUF_STR
+
+ void str (const _C_string_type &__str) {
rdbuf ()->str (__str);
}
@@ -275,6 +282,13 @@
: basic_ostream<char_type, traits_type>(rdbuf ()),
_C_sb (__str, __mode | ios_base::out) { }
+ // extension
+ _EXPLICIT
+ basic_ostringstream (const char_type *__s,
+ ios_base::openmode __mode = ios_base::out)
+ : basic_ostream<char_type, traits_type>(rdbuf ()),
+ _C_sb (__s, __mode | ios_base::out) { }
+
basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf () const {
// necessary to help SunPro 5.0/T9
typedef basic_ostringstream <char_type, traits_type, allocator_type>
@@ -286,6 +300,15 @@
return rdbuf ()->str ();
}
+#ifdef _RWSTD_NO_EXT_STRINGBUF_STR
+
+ // extension
+ void str (const char_type *__s, _RWSTD_SIZE_T __len = _RWSTD_SIZE_MAX) {
+ rdbuf ()->str (__s, __len);
+ }
+
+#endif // _RWSTD_NO_EXT_STRINGBUF_STR
+
void str (const _C_string_type &__str) {
rdbuf ()->str (__str);
}
@@ -324,6 +347,14 @@
: basic_iostream<char_type, traits_type>(rdbuf ()),
_C_sb (__str, __mode) { }
+ // extension
+ _EXPLICIT
+ basic_stringstream (const char_type *__s,
+ ios_base::openmode __mode =
+ ios_base::out | ios_base::in)
+ : basic_iostream<char_type, traits_type>(rdbuf ()),
+ _C_sb (__s, __mode) { }
+
basic_stringbuf<char_type, traits_type, allocator_type> *rdbuf () const {
// necessary to help SunPro 5.0/T9
typedef basic_stringstream <char_type, traits_type, allocator_type>
@@ -334,6 +365,15 @@
_C_string_type str () const {
return rdbuf ()->str ();
}
+
+#ifdef _RWSTD_NO_EXT_STRINGBUF_STR
+
+ // extension
+ void str (const char_type *__s, _RWSTD_SIZE_T __len = _RWSTD_SIZE_MAX) {
+ rdbuf ()->str (__s, __len);
+ }
+
+#endif // _RWSTD_NO_EXT_STRINGBUF_STR
void str (const _C_string_type &__str) {
rdbuf ()->str (__str);
Modified: incubator/stdcxx/trunk/include/sstream.cc
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/include/sstream.cc?rev=378371&r1=378370&r2=378371&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/sstream.cc (original)
+++ incubator/stdcxx/trunk/include/sstream.cc Thu Feb 16 13:23:46 2006
@@ -2,7 +2,7 @@
*
* sstream.cc - Declarations for the Standard Library basic strings
*
- * $Id: //stdlib/dev/include/sstream.cc#31 $
+ * $Id$
*
***************************************************************************
*
@@ -28,35 +28,39 @@
basic_stringbuf (const _C_string_type& __str, ios_base::openmode __mode)
: basic_streambuf<_CharT, _Traits>(__mode)
{
- typedef _RWSTD_STREAMSIZE _Streamsize;
+ str (__str);
+}
- this->_C_own_buf (true);
- const _Streamsize __slen = _Streamsize (__str.length ());
+// extension
+template<class _CharT, class _Traits, class _Allocator>
+basic_stringbuf<_CharT, _Traits, _Allocator>::
+basic_stringbuf (const char_type *__s, ios_base::openmode __mode)
+ : basic_streambuf<_CharT, _Traits>(__mode)
+{
+ _RWSTD_ASSERT (0 != __s);
- if (__slen != 0) {
+ str (__s, traits_type::length (__s));
+}
- typedef _RWSTD_ALLOC_TYPE (allocator_type, char_type) _ValueAlloc;
- this->_C_bufsize = __slen;
- this->_C_buffer = _ValueAlloc ().allocate (this->_C_bufsize);
- traits_type::copy (this->_C_buffer, __str.data (), __slen);
-
- if (this->_C_is_in ())
- this->setg (this->_C_buffer, this->_C_buffer, this->_C_buf_end ());
-
- if (this->_C_is_out ())
- this->setp (this->_C_buffer, this->_C_buf_end ());
-
- if (__mode & (ios_base::app | ios_base::ate))
- this->pbump (__slen); // "seek" to end
- }
+template <class _CharT, class _Traits, class _Allocator>
+/* virtual */
+basic_stringbuf<_CharT, _Traits, _Allocator>::
+~basic_stringbuf ()
+{
+ typedef _RWSTD_ALLOC_TYPE (allocator_type, char_type) _ValueAlloc;
+
+ if (this->_C_own_buf ())
+ _ValueAlloc ().deallocate (this->_C_buffer, this->_C_bufsize);
}
+
+// extension
template<class _CharT, class _Traits, class _Allocator>
void
basic_stringbuf<_CharT, _Traits, _Allocator>::
-str (const _C_string_type& __str)
+str (const char_type *__s, _RWSTD_SIZE_T __slen /* = -1 */)
{
_RWSTD_ASSERT (this->_C_is_valid ());
@@ -64,20 +68,22 @@
typedef _RWSTD_STREAMSIZE _Streamsize;
- const _Streamsize __slen = _Streamsize (__str.length ());
+ if (_RWSTD_SIZE_MAX == __slen)
+ __slen = traits_type::length (__s);
if (0 == __slen) {
if (this->_C_own_buf ())
_ValueAlloc ().deallocate (this->_C_buffer, this->_C_bufsize);
- this->setg(0, 0, 0);
- this->setp(0, 0);
- this->_C_buffer = 0;
+ this->setg (0, 0, 0);
+ this->setp (0, 0);
+
+ this->_C_buffer = 0;
this->_C_bufsize = 0;
}
else {
- if (__slen > this->_C_bufsize) {
+ if (this->_C_bufsize < __slen) {
// buffer too small - need to reallocate
if (this->_C_own_buf ())
@@ -88,20 +94,39 @@
this->_C_buffer = _ValueAlloc ().allocate (this->_C_bufsize);
this->_C_own_buf (true);
}
- traits_type::copy (this->_C_buffer, __str.data (), __slen);
+
+ traits_type::copy (this->_C_buffer, __s, __slen);
+
+ char_type* const __bufend = this->_C_buffer + __slen;
if (this->_C_is_in ())
- this->setg (this->_C_buffer, this->_C_buffer,
- this->_C_buffer + __slen);
+ this->setg (this->_C_buffer, this->_C_buffer, __bufend);
if (this->_C_is_out ()) {
- this->setp (this->_C_buffer, this->_C_buffer + __slen);
+ this->setp (this->_C_buffer, __bufend);
- if ( (this->_C_state & ios_base::app)
- || (this->_C_state & ios_base::ate))
- this->pbump (__slen); // seek to end
+ if (this->_C_state & (ios_base::app | ios_base::ate))
+ this->pbump (__slen); // seek to end
}
}
+}
+
+
+template <class _CharT, class _Traits, class _Allocator>
+_TYPENAME basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
+basic_stringbuf<_CharT, _Traits, _Allocator>::
+underflow ()
+{
+ _RWSTD_ASSERT (this->_C_is_valid ());
+
+ if (this->gptr () < this->egptr ()) {
+
+ _RWSTD_ASSERT (0 != this->gptr ());
+
+ return traits_type::to_int_type (*this->gptr ());
+ }
+
+ return traits_type::eof ();
}