Bugzilla – Bug 15766
optimize os.date() calls in ClockApplet
Last modified: 2010-07-19 12:47:11 UTC
advice from Michael 24Feb2010 in Campfire: Ben - you could probably reduce the number of os.date() calls in Clock by using the special format *t, returning a hash of values date = os.date("*t") if format is the string "*t", then date returns a table with the following fields: year (four digits), month (1--12), day (1--31), hour (0--23), min (0--59), sec (0--61), wday (weekday, Sunday is 1), yday (day of the year), and isdst (daylight saving flag, a boolean). optimizing os.date() calls in Clock is out of scope for 7.5.0, so opening this against 8.0 as a reminder
I spent a little time with this for fun today...what ends up happening if you pull in the os.date("*t") hash is that you end up having to call tostring() a lot instead. I'm not sure which is more expensive, but I think the value of optimizing os.date() calls for tostring() calls is small enough to say WONTFIX.
change of heart, this is probably worth doing
Created attachment 6914 [details] patch to reduce os.date() calls Michael, can you try this patch out? I tested all of the clocks and everything seems good, but wanted another set of eyes on this before checking into 7.6/trunk
Looking good to me. What made you chang your mind?
well, I'm not sure which is more expensive but I'd have to guess it's os.date(). I thought the code was cleaner with (usually) just one call to os.date() and misc string.format() and tostring() calls. I think this is safe for a 7.6 checkin.
== Auto-comment from SVN commit #8963 to the jive repo by bklaas == == http://svn.slimdevices.com/jive?view=revision&revision=8963 == Fixed Bug: 15766 Description: optimize code to reduce os.date() calls by using the *t arg to it and then manipulating the returned hash
== Auto-comment from SVN commit #8964 to the jive repo by bklaas == == http://svn.slimdevices.com/jive?view=revision&revision=8964 == Bug: 15766 Description: need leading zeroes for several strings when number < 10 time.wday counts from 1 while strings.txt counts from 0