On Wed, Jan 14, 2015 at 5:57 PM, Eli Zaretskii <[email protected]> wrote: >> Date: Wed, 14 Jan 2015 10:42:08 +0000 >> From: Gavin Smith <[email protected]> >> Cc: Texinfo <[email protected]> >> >> int >> wcwidth (wchar_t wc) >> #undef wcwidth >> { >> /* In UTF-8 locales, use a Unicode aware width function. */ >> const char *encoding = locale_charset (); >> if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0)) >> { >> /* We assume that in a UTF-8 locale, a wide character is the same as a >> Unicode character. */ >> return uc_width (wc, encoding); >> } >> else >> { >> /* Otherwise, fall back to the system's wcwidth function. */ >> #if HAVE_WCWIDTH >> return wcwidth (wc); >> #else >> return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; >> #endif >> } >> } >> >> locale_charset is always called every time. > > Yes, I know. But only if gnulib's wcwidth is used. Is it used on > your platform? AFAIK, glibc provides wcwidth, so I'd expect the > gnulib version not to be used on your platform.
Right, I was forgetting that the gnulib version won't be used if the function exists. > > In any case, I don't see why we need to call locale_charset for each > and every character, over and over and over again. We should call it > once and then reuse the result, since it depends on the environment > outside the reader, and will not change during the session, right? I raised this issue on the gnulib list here: http://lists.gnu.org/archive/html/bug-gnulib/2015-01/msg00040.html. One idea is to add another function to gnulib where the encoding is passed as a parameter.
