Commit a8ea7389 by Paolo Carlini Committed by Paolo Carlini

locale_facets.tcc (num_get<>::_M_extract_float, [...]): If appropriate, call…

locale_facets.tcc (num_get<>::_M_extract_float, [...]): If appropriate, call reserve on the __tmp_gruping string.

2004-02-27  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (num_get<>::_M_extract_float,
	num_get<>::_M_extract_int, money_get<>::_M_extract): If appropriate,
	call reserve on the __tmp_gruping string.
	(num_get<>::_M_extract_float): Don't append unnecessarily a
	char() to the returned string.
	* include/bits/locale_facets.tcc: Trivial reformattings.

From-SVN: r78565
parent 53c428d0
2004-02-27 Paolo Carlini <pcarlini@suse.de> 2004-02-27 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.tcc (num_get<>::_M_extract_float,
num_get<>::_M_extract_int, money_get<>::_M_extract): If appropriate,
call reserve on the __tmp_gruping string.
(num_get<>::_M_extract_float): Don't append unnecessarily a
char() to the returned string.
* include/bits/locale_facets.tcc: Trivial reformattings.
2004-02-27 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.h (money_get<>::_M_extract): * include/bits/locale_facets.h (money_get<>::_M_extract):
Change signature: now takes a plain string&. Change signature: now takes a plain string&.
* include/bits/locale_facets.tcc (money_get<>::_M_extract): * include/bits/locale_facets.tcc (money_get<>::_M_extract):
......
...@@ -219,9 +219,11 @@ namespace std ...@@ -219,9 +219,11 @@ namespace std
bool __found_dec = false; bool __found_dec = false;
bool __found_sci = false; bool __found_sci = false;
string __found_grouping; string __found_grouping;
if (__lc->_M_use_grouping)
__found_grouping.reserve(32);
int __sep_pos = 0; int __sep_pos = 0;
bool __e; bool __e;
const char_type* __p; const char_type* __q;
while (__beg != __end) while (__beg != __end)
{ {
// According to 22.2.2.1.2, p8-9, first look for thousands_sep // According to 22.2.2.1.2, p8-9, first look for thousands_sep
...@@ -265,9 +267,9 @@ namespace std ...@@ -265,9 +267,9 @@ namespace std
else else
break; break;
} }
else if (__p = __traits_type::find(__lit + _S_izero, 10, __c)) else if (__q = __traits_type::find(__lit + _S_izero, 10, __c))
{ {
__xtrc += _S_atoms_in[__p - __lit]; __xtrc += _S_atoms_in[__q - __lit];
__found_mantissa = true; __found_mantissa = true;
++__sep_pos; ++__sep_pos;
++__beg; ++__beg;
...@@ -283,7 +285,8 @@ namespace std ...@@ -283,7 +285,8 @@ namespace std
// Remove optional plus or minus sign, if they exist. // Remove optional plus or minus sign, if they exist.
if (++__beg != __end) if (++__beg != __end)
{ {
const bool __plus = __traits_type::eq(*__beg, __lit[_S_iplus]); const bool __plus = __traits_type::eq(*__beg,
__lit[_S_iplus]);
if (__plus || __traits_type::eq(*__beg, __lit[_S_iminus])) if (__plus || __traits_type::eq(*__beg, __lit[_S_iminus]))
{ {
__xtrc += __plus ? _S_atoms_in[_S_iplus] __xtrc += __plus ? _S_atoms_in[_S_iplus]
...@@ -311,7 +314,6 @@ namespace std ...@@ -311,7 +314,6 @@ namespace std
} }
// Finish up. // Finish up.
__xtrc += char();
if (__beg == __end) if (__beg == __end)
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
return __beg; return __beg;
...@@ -332,7 +334,8 @@ namespace std ...@@ -332,7 +334,8 @@ namespace std
const _CharT* __lit = __lc->_M_atoms_in; const _CharT* __lit = __lc->_M_atoms_in;
// NB: Iff __basefield == 0, __base can change based on contents. // NB: Iff __basefield == 0, __base can change based on contents.
const ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield; const ios_base::fmtflags __basefield = __io.flags()
& ios_base::basefield;
const bool __oct = __basefield == ios_base::oct; const bool __oct = __basefield == ios_base::oct;
int __base = __oct ? 8 : (__basefield == ios_base::hex ? 16 : 10); int __base = __oct ? 8 : (__basefield == ios_base::hex ? 16 : 10);
...@@ -395,11 +398,13 @@ namespace std ...@@ -395,11 +398,13 @@ namespace std
// Extract. // Extract.
string __found_grouping; string __found_grouping;
if (__lc->_M_use_grouping)
__found_grouping.reserve(32);
int __sep_pos = 0; int __sep_pos = 0;
bool __overflow = false; bool __overflow = false;
_ValueT __result = 0; _ValueT __result = 0;
const char_type* __lit_zero = __lit + _S_izero; const char_type* __lit_zero = __lit + _S_izero;
const char_type* __p; const char_type* __q;
if (__negative) if (__negative)
{ {
const _ValueT __min = numeric_limits<_ValueT>::min() / __base; const _ValueT __min = numeric_limits<_ValueT>::min() / __base;
...@@ -426,16 +431,17 @@ namespace std ...@@ -426,16 +431,17 @@ namespace std
} }
else if (__traits_type::eq(__c, __lc->_M_decimal_point)) else if (__traits_type::eq(__c, __lc->_M_decimal_point))
break; break;
else if (__p = __traits_type::find(__lit_zero, __len, __c)) else if (__q = __traits_type::find(__lit_zero, __len, __c))
{ {
int __digit = __p - __lit_zero; int __digit = __q - __lit_zero;
if (__digit > 15) if (__digit > 15)
__digit -= 6; __digit -= 6;
if (__result < __min) if (__result < __min)
__overflow = true; __overflow = true;
else else
{ {
const _ValueT __new_result = __result * __base - __digit; const _ValueT __new_result = __result * __base
- __digit;
__overflow |= __new_result > __result; __overflow |= __new_result > __result;
__result = __new_result; __result = __new_result;
++__sep_pos; ++__sep_pos;
...@@ -469,16 +475,17 @@ namespace std ...@@ -469,16 +475,17 @@ namespace std
} }
else if (__traits_type::eq(__c, __lc->_M_decimal_point)) else if (__traits_type::eq(__c, __lc->_M_decimal_point))
break; break;
else if (__p = __traits_type::find(__lit_zero, __len, __c)) else if (__q = __traits_type::find(__lit_zero, __len, __c))
{ {
int __digit = __p - __lit_zero; int __digit = __q - __lit_zero;
if (__digit > 15) if (__digit > 15)
__digit -= 6; __digit -= 6;
if (__result > __max) if (__result > __max)
__overflow = true; __overflow = true;
else else
{ {
const _ValueT __new_result = __result * __base + __digit; const _ValueT __new_result = __result * __base
+ __digit;
__overflow |= __new_result < __result; __overflow |= __new_result < __result;
__result = __new_result; __result = __new_result;
++__sep_pos; ++__sep_pos;
...@@ -497,7 +504,8 @@ namespace std ...@@ -497,7 +504,8 @@ namespace std
// Add the ending grouping. // Add the ending grouping.
__found_grouping += static_cast<char>(__sep_pos); __found_grouping += static_cast<char>(__sep_pos);
if (!std::__verify_grouping(__lc->_M_grouping, __lc->_M_grouping_size, if (!std::__verify_grouping(__lc->_M_grouping,
__lc->_M_grouping_size,
__found_grouping)) __found_grouping))
__err |= ios_base::failbit; __err |= ios_base::failbit;
} }
...@@ -890,8 +898,9 @@ namespace std ...@@ -890,8 +898,9 @@ namespace std
template<typename _CharT, typename _OutIter> template<typename _CharT, typename _OutIter>
void void
num_put<_CharT, _OutIter>:: num_put<_CharT, _OutIter>::
_M_group_float(const char* __grouping, size_t __grouping_size, _CharT __sep, _M_group_float(const char* __grouping, size_t __grouping_size,
const _CharT* __p, _CharT* __new, _CharT* __cs, int& __len) const _CharT __sep, const _CharT* __p, _CharT* __new,
_CharT* __cs, int& __len) const
{ {
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// 282. What types does numpunct grouping refer to? // 282. What types does numpunct grouping refer to?
...@@ -1061,8 +1070,9 @@ namespace std ...@@ -1061,8 +1070,9 @@ namespace std
const streamsize __w = __io.width(); const streamsize __w = __io.width();
if (__w > static_cast<streamsize>(__len)) if (__w > static_cast<streamsize>(__len))
{ {
_CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) _CharT* __cs
* __w)); = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
* __w));
_M_pad(__fill, __w, __io, __cs, __name, __len); _M_pad(__fill, __w, __io, __cs, __name, __len);
__name = __cs; __name = __cs;
} }
...@@ -1120,8 +1130,10 @@ namespace std ...@@ -1120,8 +1130,10 @@ namespace std
const void* __v) const const void* __v) const
{ {
const ios_base::fmtflags __flags = __io.flags(); const ios_base::fmtflags __flags = __io.flags();
const ios_base::fmtflags __fmt = ~(ios_base::showpos | ios_base::basefield const ios_base::fmtflags __fmt = ~(ios_base::showpos
| ios_base::uppercase | ios_base::internal); | ios_base::basefield
| ios_base::uppercase
| ios_base::internal);
__io.flags(__flags & __fmt | (ios_base::hex | ios_base::showbase)); __io.flags(__flags & __fmt | (ios_base::hex | ios_base::showbase));
__s = _M_insert_int(__s, __io, __fill, __s = _M_insert_int(__s, __io, __fill,
...@@ -1186,6 +1198,8 @@ namespace std ...@@ -1186,6 +1198,8 @@ namespace std
bool __long_sign = false; bool __long_sign = false;
// String of grouping info from thousands_sep plucked from __units. // String of grouping info from thousands_sep plucked from __units.
string __grouping_tmp; string __grouping_tmp;
if (__lc->_M_use_grouping)
__grouping_tmp.reserve(32);
// Marker for thousands_sep position. // Marker for thousands_sep position.
int __sep_pos = 0; int __sep_pos = 0;
// If input iterator is in a valid state. // If input iterator is in a valid state.
...@@ -1274,9 +1288,10 @@ namespace std ...@@ -1274,9 +1288,10 @@ namespace std
__sep_pos = 0; __sep_pos = 0;
__testdecfound = true; __testdecfound = true;
} }
else if (*__beg == __lc->_M_thousands_sep && !__testdecfound) else if (__lc->_M_use_grouping
&& *__beg == __lc->_M_thousands_sep)
{ {
if (__lc->_M_grouping_size) if (!__testdecfound)
{ {
// Mark position for later analysis. // Mark position for later analysis.
__grouping_tmp += static_cast<char>(__sep_pos); __grouping_tmp += static_cast<char>(__sep_pos);
...@@ -2146,8 +2161,9 @@ namespace std ...@@ -2146,8 +2161,9 @@ namespace std
// NB: This size is arbitrary. Should this be a data member, // NB: This size is arbitrary. Should this be a data member,
// initialized at construction? // initialized at construction?
const size_t __maxlen = 64; const size_t __maxlen = 64;
char_type* __res = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) char_type* __res =
* __maxlen)); static_cast<char_type*>(__builtin_alloca(sizeof(char_type)
* __maxlen));
// NB: In IEE 1003.1-200x, and perhaps other locale models, it // NB: In IEE 1003.1-200x, and perhaps other locale models, it
// is possible that the format character will be longer than one // is possible that the format character will be longer than one
......
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