locale_facets.tcc (time_get::do_get_year): Avoid using a basic_string and calling a full blown strtol (via __convert_to_v)...

2003-12-02  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (time_get::do_get_year):
	Avoid using a basic_string and calling a full blown strtol
	(via __convert_to_v) for simple 2 or 4 digits, base 10,
	positive integers; simplify.

From-SVN: r74193
This commit is contained in:
Paolo Carlini 2003-12-02 18:30:42 +00:00 committed by Paolo Carlini
parent 0548bb4aba
commit 17e15f7f3b
2 changed files with 16 additions and 13 deletions

View File

@ -1,3 +1,10 @@
2003-12-02 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.tcc (time_get::do_get_year):
Avoid using a basic_string and calling a full blown strtol
(via __convert_to_v) for simple 2 or 4 digits, base 10,
positive integers; simplify.
2003-12-02 Paolo Carlini <pcarlini@suse.de>
* config/locale/gnu/monetary_members.cc

View File

@ -1964,21 +1964,17 @@ namespace std
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
size_t __i = 0;
string __digits;
for (; __i < 4 && __beg != __end
&& __ctype.is(ctype_base::digit, *__beg); ++__beg, ++__i)
__digits += __ctype.narrow(*__beg, 0);
if (__i == 2 || __i == 4)
int __value = 0;
for (; __beg != __end && __i < 4; ++__beg, ++__i)
{
long __l;
std::__convert_to_v(__digits.c_str(), __l, __err,
_S_get_c_locale());
if (!(__err & ios_base::failbit) && __l <= INT_MAX)
{
__l = __i == 2 ? __l : __l - 1900;
__tm->tm_year = static_cast<int>(__l);
}
const char __c = __ctype.narrow(*__beg, '*');
if (__c >= '0' && __c <= '9')
__value = __value * 10 + (__c - '0');
else
break;
}
if (__i == 2 || __i == 4)
__tm->tm_year = __i == 2 ? __value : __value - 1900;
else
__err |= ios_base::failbit;
if (__beg == __end)