This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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]

[PATCH] libc/time/gmtime_r.c, libc/time/lcltime_r.c,, libc/time/local.h, libc/time/mktm_r.c: move localtime related functionality, from _mktm_r() to new _mklocaltm_r() to break dependency of gmtime() on, timezones


Hello again (;

I attach patch and a ChangeLog entry with a bigger change to time-related sources.

Currently functions gmtime() and localtime() are both implemented with common code in _mktm_r(), which decides whether to do time zone adjustments by additional parameter - is_gmtime, true for gmtime() and false for localtime(). This way if you use gmtime() and don't care about time zones, you get them anyway in the final binary.

This change moves all time zone related stuff from _mktm_r() to new function _mklocaltm_r(). gmtime_r() still calls _mktm_r() (but with this boolean parameter removed), while localtime_r() first calls _mktm_r() and then calls _mklocaltm_r() using the result of _mktm_r().

This way you get time zone stuff in the final link only if it's really needed - when you use localtime(). If you use just gmtime(), the time zone functions are not linked, which saves about 1kB of flash and a little below 100B of RAM (on ARM Cortex-M3). (the savings would be bigger if proper locks are implemented - by default only stubs are used and no code for mutexes is needed)

Actually the names of the functions are not 100% good, but changing the name of _mktm_r() to something clearer (_mkgmtime_r()?) should come with changing the name of the source file, so I decided to leave that as it is... If you think that the names should change too, I could modify the patch and extend it.

Regards,
FCh

Attachment: 0001-libc-time-gmtime_r.c-libc-time-lcltime_r.c-libc-time.patch
Description: Text document

Attachment: ChangeLog.txt
Description: Text document


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