This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Fix libstdc++/12439


Nathan Myers wrote:

...
template<typename _CharT, typename _OutIter>
_OutIter
time_put<_CharT, _OutIter>::
- put(iter_type __s, ios_base& __io, char_type, const tm* __tm, + put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, const _CharT* __beg, const _CharT* __end) const
{
locale __loc = __io.getloc();
ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
while (__beg != __end)
{
- char __c = __ctype.narrow(*__beg, 0);
+ const _CharT* __tmp = __beg;
++__beg;
- if (__c == '%')
+ if (__ctype.narrow(*__tmp, 0) == '%' && __beg != __end)
{
char __format;
char __mod = 0;
- size_t __len = 1; - __c = __ctype.narrow(*__beg, 0);
+ const char __c = __ctype.narrow(*__beg, 0);
++__beg;
if (__c == 'E' || __c == 'O')
{


First, why is this (still) calling narrow in a loop to identify
the '%' marker? It should call widen once at the top, and compare the characters found against the widened version. Likewise the 'E' and 'O'.

You know why -- because 22.2.5.3.1, p1 says so ;-) I understand what you're saying but this is the same old problem with the facets not knowing how to compare arbitrary charT's and there being no _explicit_ requirements on charT's comparability.

We really ought to fix the standard before making these kinds of
choices, otherwise there is no portability with implementations
that do follow the existing requirements. Issue 427 tries to do
this for num_get(*). Maybe there needs to be one for the other
facets, too (although the proposed resolution of 427 is contrary
to what you're suggesting here).

http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#427

Incidentally, the call to narrow() need not be as expensive as
it might seem -- the char specialization is essentially a noop
and the wchar_t specialization can be optimized for the common
case (wide character values between 0 and 255) to a couple of
ifs followed by an indexed read:

    inline char ctype<wchar_t>::narrow (wchar_t wc, char deflt) {
        unsigned wi = wc;
        if (wi < 256) {
            if (narrow_table_ [wi])
                return narrow_table_ [wi];
            return narrow_table_ [wi] = do_narrow (wc, deflt);
        }
        return do_narrow (wc, deflt);
    }

Regards
Martin



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]