Commit adb31ad6 by Paolo Carlini Committed by Paolo Carlini

istream.tcc (getline(char_type*, streamsize, char_type), [...]): Restore a…

istream.tcc (getline(char_type*, streamsize, char_type), [...]): Restore a generic version of the functions...

2004-11-08  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/istream.tcc (getline(char_type*, streamsize,
	char_type), ignore(streamsize), ignore(streamsize, int_type)):
	Restore a generic version of the functions, not using the
	protected members of basic_streambuf.
	* include/std/std_istream.h (getline(char_type*, streamsize,
	char_type), ignore(streamsize), ignore(streamsize, int_type)):
	Declare optimized specializations for char and wchar_t.
	* src/istream.cc: New file, define the latter.
	* src/Makefile.am: Add.
	* src/Makefile.in: Regenerate.

From-SVN: r90268
parent 1b7cd4a5
2004-11-08 Paolo Carlini <pcarlini@suse.de>
* include/bits/istream.tcc (getline(char_type*, streamsize,
char_type), ignore(streamsize), ignore(streamsize, int_type)):
Restore a generic version of the functions, not using the
protected members of basic_streambuf.
* include/std/std_istream.h (getline(char_type*, streamsize,
char_type), ignore(streamsize), ignore(streamsize, int_type)):
Declare optimized specializations for char and wchar_t.
* src/istream.cc: New file, define the latter.
* src/Makefile.am: Add.
* src/Makefile.in: Regenerate.
2004-11-07 Paolo Carlini <pcarlini@suse.de> 2004-11-07 Paolo Carlini <pcarlini@suse.de>
* testsuite/performance/27_io/ifstream_getline-2.cc: New. * testsuite/performance/27_io/ifstream_getline-2.cc: New.
......
...@@ -596,41 +596,23 @@ namespace std ...@@ -596,41 +596,23 @@ namespace std
&& !traits_type::eq_int_type(__c, __eof) && !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __idelim)) && !traits_type::eq_int_type(__c, __idelim))
{ {
streamsize __size = std::min(streamsize(__sb->egptr()
- __sb->gptr()),
streamsize(__n - _M_gcount
- 1));
if (__size > 1)
{
const char_type* __p = traits_type::find(__sb->gptr(),
__size,
__delim);
if (__p)
__size = __p - __sb->gptr();
traits_type::copy(__s, __sb->gptr(), __size);
__s += __size;
__sb->gbump(__size);
_M_gcount += __size;
__c = __sb->sgetc();
}
else
{
*__s++ = traits_type::to_char_type(__c); *__s++ = traits_type::to_char_type(__c);
++_M_gcount;
__c = __sb->snextc(); __c = __sb->snextc();
++_M_gcount;
} }
}
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
else if (traits_type::eq_int_type(__c, __idelim)) else
{
if (traits_type::eq_int_type(__c, __idelim))
{ {
++_M_gcount;
__sb->sbumpc(); __sb->sbumpc();
++_M_gcount;
} }
else else
__err |= ios_base::failbit; __err |= ios_base::failbit;
} }
}
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
} }
...@@ -690,30 +672,13 @@ namespace std ...@@ -690,30 +672,13 @@ namespace std
{ {
const int_type __eof = traits_type::eof(); const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c = __eof;
const bool __bound = __n != numeric_limits<streamsize>::max(); if (__n != numeric_limits<streamsize>::max())
if (__bound)
--__n; --__n;
while (_M_gcount <= __n while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c, __eof)) && !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
{
streamsize __size = __sb->egptr() - __sb->gptr();
if (__bound)
__size = std::min(__size, streamsize(__n - _M_gcount + 1));
if (__size > 1)
{
__sb->gbump(__size);
_M_gcount += __size;
__c = __sb->sgetc();
}
else
{
++_M_gcount; ++_M_gcount;
__c = __sb->snextc();
}
}
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
} }
...@@ -740,46 +705,21 @@ namespace std ...@@ -740,46 +705,21 @@ namespace std
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try try
{ {
const char_type __cdelim = traits_type::to_char_type(__delim);
const int_type __eof = traits_type::eof(); const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c = __eof;
const bool __bound = __n != numeric_limits<streamsize>::max(); if (__n != numeric_limits<streamsize>::max())
if (__bound)
--__n; --__n;
while (_M_gcount <= __n while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c, __eof) && !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
&& !traits_type::eq_int_type(__c, __delim))
{
streamsize __size = __sb->egptr() - __sb->gptr();
if (__bound)
__size = std::min(__size, streamsize(__n - _M_gcount + 1));
if (__size > 1)
{
const char_type* __p = traits_type::find(__sb->gptr(),
__size,
__cdelim);
if (__p)
__size = __p - __sb->gptr();
__sb->gbump(__size);
_M_gcount += __size;
__c = __sb->sgetc();
}
else
{ {
++_M_gcount; ++_M_gcount;
__c = __sb->snextc(); if (traits_type::eq_int_type(__c, __delim))
} break;
} }
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
else if (traits_type::eq_int_type(__c, __delim))
{
++_M_gcount;
__sb->sbumpc();
}
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
......
...@@ -575,6 +575,39 @@ namespace std ...@@ -575,6 +575,39 @@ namespace std
basic_istream(): _M_gcount(streamsize(0)) { } basic_istream(): _M_gcount(streamsize(0)) { }
}; };
// Explicit specialization declarations, defined in src/istream.cc.
template<>
basic_istream<char>&
basic_istream<char>::
getline(char_type* __s, streamsize __n, char_type __delim);
template<>
basic_istream<char>&
basic_istream<char>::
ignore(streamsize __n);
template<>
basic_istream<char>&
basic_istream<char>::
ignore(streamsize __n, int_type __delim);
#ifdef _GLIBCXX_USE_WCHAR_T
template<>
basic_istream<wchar_t>&
basic_istream<wchar_t>::
getline(char_type* __s, streamsize __n, char_type __delim);
template<>
basic_istream<wchar_t>&
basic_istream<wchar_t>::
ignore(streamsize __n);
template<>
basic_istream<wchar_t>&
basic_istream<wchar_t>::
ignore(streamsize __n, int_type __delim);
#endif
/** /**
* @brief Performs setup work for input streams. * @brief Performs setup work for input streams.
* *
...@@ -693,13 +726,13 @@ namespace std ...@@ -693,13 +726,13 @@ namespace std
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s); operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
template<class _Traits> template<class _Traits>
basic_istream<char,_Traits>& basic_istream<char, _Traits>&
operator>>(basic_istream<char,_Traits>& __in, unsigned char* __s) operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
{ return (__in >> reinterpret_cast<char*>(__s)); } { return (__in >> reinterpret_cast<char*>(__s)); }
template<class _Traits> template<class _Traits>
basic_istream<char,_Traits>& basic_istream<char, _Traits>&
operator>>(basic_istream<char,_Traits>& __in, signed char* __s) operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
{ return (__in >> reinterpret_cast<char*>(__s)); } { return (__in >> reinterpret_cast<char*>(__s)); }
//@} //@}
......
...@@ -126,6 +126,7 @@ sources = \ ...@@ -126,6 +126,7 @@ sources = \
ext-inst.cc \ ext-inst.cc \
io-inst.cc \ io-inst.cc \
istream-inst.cc \ istream-inst.cc \
istream.cc \
locale-inst.cc \ locale-inst.cc \
locale-misc-inst.cc \ locale-misc-inst.cc \
misc-inst.cc \ misc-inst.cc \
......
...@@ -71,8 +71,8 @@ am__objects_3 = bitmap_allocator.lo pool_allocator.lo mt_allocator.lo \ ...@@ -71,8 +71,8 @@ am__objects_3 = bitmap_allocator.lo pool_allocator.lo mt_allocator.lo \
locale.lo locale_init.lo locale_facets.lo localename.lo \ locale.lo locale_init.lo locale_facets.lo localename.lo \
stdexcept.lo strstream.lo tree.lo allocator-inst.lo \ stdexcept.lo strstream.lo tree.lo allocator-inst.lo \
concept-inst.lo fstream-inst.lo ext-inst.lo io-inst.lo \ concept-inst.lo fstream-inst.lo ext-inst.lo io-inst.lo \
istream-inst.lo locale-inst.lo locale-misc-inst.lo misc-inst.lo \ istream-inst.lo istream.lo locale-inst.lo locale-misc-inst.lo \
ostream-inst.lo sstream-inst.lo streambuf-inst.lo \ misc-inst.lo ostream-inst.lo sstream-inst.lo streambuf-inst.lo \
string-inst.lo valarray-inst.lo wlocale-inst.lo \ string-inst.lo valarray-inst.lo wlocale-inst.lo \
wstring-inst.lo $(am__objects_1) $(am__objects_2) wstring-inst.lo $(am__objects_1) $(am__objects_2)
am_libstdc___la_OBJECTS = $(am__objects_3) am_libstdc___la_OBJECTS = $(am__objects_3)
...@@ -336,6 +336,7 @@ sources = \ ...@@ -336,6 +336,7 @@ sources = \
ext-inst.cc \ ext-inst.cc \
io-inst.cc \ io-inst.cc \
istream-inst.cc \ istream-inst.cc \
istream.cc \
locale-inst.cc \ locale-inst.cc \
locale-misc-inst.cc \ locale-misc-inst.cc \
misc-inst.cc \ misc-inst.cc \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment