locale_facets.h (struct __numpunct_cache): Add members _M_truename_len and _M_falsename_len...

2004-01-12  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.h (struct __numpunct_cache):
	Add members _M_truename_len and _M_falsename_len, caching
	the lengths of _M_truename and _M_falsename.
	(__numpunct_cache<>::_M_cache): Assign the latter.
	* include/bits/locale_facets.tcc (num_get::do_get(bool&),
	num_put::do_put(bool)): Use the new members, thus avoiding
	computing string lengths again and again.
	* config/locale/generic/numeric_members.cc
	(numpunct<>::_M_initialize_numpunct): Assign the new members.
	* config/locale/gnu/numeric_members.cc
	(numpunct<>::_M_initialize_numpunct): Likewise.

From-SVN: r75735
This commit is contained in:
Paolo Carlini 2004-01-12 17:02:08 +00:00 committed by Paolo Carlini
parent 59774bb047
commit dc6798f865
5 changed files with 41 additions and 20 deletions

View File

@ -1,3 +1,17 @@
2004-01-12 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.h (struct __numpunct_cache):
Add members _M_truename_len and _M_falsename_len, caching
the lengths of _M_truename and _M_falsename.
(__numpunct_cache<>::_M_cache): Assign the latter.
* include/bits/locale_facets.tcc (num_get::do_get(bool&),
num_put::do_put(bool)): Use the new members, thus avoiding
computing string lengths again and again.
* config/locale/generic/numeric_members.cc
(numpunct<>::_M_initialize_numpunct): Assign the new members.
* config/locale/gnu/numeric_members.cc
(numpunct<>::_M_initialize_numpunct): Likewise.
2004-01-12 Mark Mitchell <mark@codesourcery.com>
* testsuite/testsuite_hooks.h (__gnu_test::try_mkfifo): Declare it.

View File

@ -58,7 +58,9 @@ namespace std
_M_data->_M_atoms_in[__i] = __num_base::_S_atoms_in[__i];
_M_data->_M_truename = "true";
_M_data->_M_falsename = "false";
_M_data->_M_truename_len = strlen(_M_data->_M_truename);
_M_data->_M_falsename = "false";
_M_data->_M_falsename_len = strlen(_M_data->_M_falsename);
}
template<>
@ -95,7 +97,9 @@ namespace std
}
_M_data->_M_truename = L"true";
_M_data->_M_truename_len = wcslen(_M_data->_M_truename);
_M_data->_M_falsename = L"false";
_M_data->_M_falsename_len = wcslen(_M_data->_M_falsename);
}
template<>

View File

@ -75,8 +75,10 @@ namespace std
// NB: There is no way to extact this info from posix locales.
// _M_truename = __nl_langinfo_l(YESSTR, __cloc);
_M_data->_M_truename = "true";
_M_data->_M_truename_len = strlen(_M_data->_M_truename);
// _M_falsename = __nl_langinfo_l(NOSTR, __cloc);
_M_data->_M_falsename = "false";
_M_data->_M_falsename_len = strlen(_M_data->_M_falsename);
}
template<>
@ -138,8 +140,10 @@ namespace std
// NB: There is no way to extact this info from posix locales.
// _M_truename = __nl_langinfo_l(YESSTR, __cloc);
_M_data->_M_truename = L"true";
_M_data->_M_truename_len = wcslen(_M_data->_M_truename);
// _M_falsename = __nl_langinfo_l(NOSTR, __cloc);
_M_data->_M_falsename = L"false";
_M_data->_M_falsename_len = wcslen(_M_data->_M_falsename);
}
template<>

View File

@ -1605,6 +1605,8 @@ namespace std
bool _M_use_grouping;
const _CharT* _M_truename;
const _CharT* _M_falsename;
size_t _M_truename_len;
size_t _M_falsename_len;
_CharT _M_decimal_point;
_CharT _M_thousands_sep;
@ -1624,8 +1626,9 @@ namespace std
__numpunct_cache(size_t __refs = 0) : facet(__refs),
_M_grouping(NULL), _M_use_grouping(false), _M_truename(NULL),
_M_falsename(NULL), _M_decimal_point(_CharT()),
_M_thousands_sep(_CharT()), _M_allocated(false)
_M_falsename(NULL), _M_truename_len(0), _M_falsename_len(0),
_M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
_M_allocated(false)
{ }
~__numpunct_cache();
@ -1649,17 +1652,14 @@ namespace std
_M_grouping = __grouping;
_M_use_grouping = __len && __np.grouping()[0] != 0;
typedef basic_string<_CharT> __string_type;
typename __string_type::size_type __lentf = __np.truename().size();
_CharT* __truename = new _CharT[__lentf + 1];
__np.truename().copy(__truename, __lentf);
__truename[__lentf] = _CharT();
_M_truename_len = __np.truename().size();
_CharT* __truename = new _CharT[_M_truename_len];
__np.truename().copy(__truename, _M_truename_len);
_M_truename = __truename;
__lentf = __np.falsename().size();
_CharT* __falsename = new _CharT[__lentf + 1];
__np.falsename().copy(__falsename, __lentf);
__falsename[__lentf] = _CharT();
_M_falsename_len = __np.falsename().size();
_CharT* __falsename = new _CharT[_M_falsename_len];
__np.falsename().copy(__falsename, _M_falsename_len);
_M_falsename = __falsename;
_M_decimal_point = __np.decimal_point();

View File

@ -529,8 +529,6 @@ namespace std
__use_cache<__cache_type> __uc;
const locale& __loc = __io._M_getloc();
const __cache_type* __lc = __uc(__loc);
const size_t __tn = __traits_type::length(__lc->_M_truename);
const size_t __fn = __traits_type::length(__lc->_M_falsename);
bool __testf = true;
bool __testt = true;
@ -538,13 +536,13 @@ namespace std
for (__n = 0; __beg != __end; ++__n, ++__beg)
{
if (__testf)
if (__n < __fn)
if (__n < __lc->_M_falsename_len)
__testf = __traits_type::eq(*__beg, __lc->_M_falsename[__n]);
else
break;
if (__testt)
if (__n < __tn)
if (__n < __lc->_M_truename_len)
__testt = __traits_type::eq(*__beg, __lc->_M_truename[__n]);
else
break;
@ -552,9 +550,9 @@ namespace std
if (!__testf && !__testt)
break;
}
if (__testf && __n == __fn)
if (__testf && __n == __lc->_M_falsename_len)
__v = 0;
else if (__testt && __n == __tn)
else if (__testt && __n == __lc->_M_truename_len)
__v = 1;
else
__err |= ios_base::failbit;
@ -1048,7 +1046,8 @@ namespace std
const _CharT* __name = __v ? __lc->_M_truename
: __lc->_M_falsename;
int __len = char_traits<_CharT>::length(__name);
int __len = __v ? __lc->_M_truename_len
: __lc->_M_falsename_len;
const streamsize __w = __io.width();
if (__w > static_cast<streamsize>(__len))