After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 83145 - g_date_strftime optimization
g_date_strftime optimization
Status: RESOLVED INCOMPLETE
Product: glib
Classification: Platform
Component: general
2.0.x
Other other
: Normal minor
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2002-05-27 10:13 UTC by Gediminas Paulauskas
Modified: 2011-02-18 16:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
g_date_strftime optimization (1.47 KB, patch)
2002-05-27 10:13 UTC, Gediminas Paulauskas
none Details | Review

Description Gediminas Paulauskas 2002-05-27 10:13:01 UTC
Current implementation always converts to locale encoding and uses strftime.
On newer systems there is wcsftime, which works on UTF-8 strings, so no
conversion is needed. The attached patch makes use wcsftime if it is available.
Comment 1 Gediminas Paulauskas 2002-05-27 10:13:58 UTC
Created attachment 8753 [details] [review]
g_date_strftime optimization
Comment 2 Matthias Clasen 2002-05-27 10:26:27 UTC
This looks wrong; UTF-8 is a multi-byte encoding, not a wide character
encoding. So 
either we have to use a "mb" function, or stick an
mbtowcs in there.
Comment 3 Gediminas Paulauskas 2002-05-27 12:43:12 UTC
Oh, it is wrong :( Just tested myself.

But converting to and from locale charset is also wrong.

When I do

  mbstowcs(formatw, format, sizeof(formatw));
  wcsftime(bufferw, sizeof(bufferw), formatw, tm);
  wcstombs(buffer, bufferw, sizeof(buffer));

I get back a string in locale encoding, not UTF-8 as I expected.

How could I implement this without converting to locale encoding, and
still operate only on UTF-8 strings?

Having such problems I certainly want g_utf8_strftime (bug 69140),
because switching to locale encoding just to format time every second
is nonsense. Just look into panel clock :(
Comment 4 Owen Taylor 2002-05-28 01:37:54 UTC
Note that g_date_strftime() does not currently switch
encodings; it just converts the format string to the
encoding of the locale and back.

There actually used to be an optiimzation in g_date_strftime()
if the encoding of the locale was UTF-8, but we decided
that the buffer handling in strftime() was so badly
messed up that it was better to have one codepath than
two.

See gunicollate.c:g_utf8_collate() for an example
of using wcs functions to implement UTF-8 functions correctly; 
however I think for g_date_strftime() the "buffer handling
is too hard to duplicate twice" argument probably
applies for this as well.

For a g_format_time() or somethign with reasonable buffer
semantics, doing optimizaitons would make more sense.


Comment 5 Owen Taylor 2002-06-11 20:25:04 UTC
Does this bug need to stay open?
Comment 6 Gediminas Paulauskas 2002-11-14 17:58:49 UTC
So the patch is wrong, g_date_strftime works as it is, closing the bug.