This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/13341] New: ctype<wchar_t>::do_narrow(wchar_t, char) is slow
- From: "paolo at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Dec 2003 17:09:17 -0000
- Subject: [Bug libstdc++/13341] New: ctype<wchar_t>::do_narrow(wchar_t, char) is slow
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Consider the following code: it shows that by building at construction time
a simple table for all the wchar_t from 0 to 128, the speed of narrow can be
increased by a factor of 10 in the common case.
Similarly for the array version and for widen (both single char and array).
///////////////////////////
#include <cwchar>
#include <locale>
struct CtypeS: std::ctype<wchar_t>
{
char
do_narrow(wchar_t __wc, char __dfault) const
{
int __c = wctob(__wc);
return (__c == EOF ? __dfault : static_cast<char>(__c));
}
};
struct CtypeF: std::ctype<wchar_t>
{
int cached[128];
char
do_narrow(wchar_t __wc, char __dfault) const
{
int __c;
if (__wc < 128)
__c = cached[__wc];
else
__c = wctob(__wc);
return (__c == EOF ? __dfault : static_cast<char>(__c));
}
};
int main()
{
using namespace std;
//locale loc = locale(locale::classic(), new CtypeF);
locale loc = locale(locale::classic(), new CtypeS);
const ctype<wchar_t>& ct = use_facet<ctype<wchar_t> >(loc);
for (long i = 0; i < 100000000; ++i)
ct.narrow(i % 128, '*');
}
//////////////////////////
--
Summary: ctype<wchar_t>::do_narrow(wchar_t, char) is slow
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libstdc++
AssignedTo: paolo at gcc dot gnu dot org
ReportedBy: paolo at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: Any
GCC target triplet: Any
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13341