ruby-changes:11634
From: akr <ko1@a...>
Date: Sat, 25 Apr 2009 15:25:21 +0900 (JST)
Subject: [ruby-changes:11634] Ruby:r23271 (trunk): * time.c (TIME_UTC_P): new macro..
akr 2009-04-25 15:25:06 +0900 (Sat, 25 Apr 2009) New Revision: 23271 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23271 Log: * time.c (TIME_UTC_P): new macro.. (TIME_SET_UTC): ditto. (TIME_LOCALTIME_P): ditto. (TIME_SET_LOCALTIME): ditto. (time_utc_p): use the above macro. (time_localtime): ditto. (time_localtime): ditto. (time_gmtime): ditto. (time_to_s): ditto. (time_add): ditto. (time_sec): ditto. (time_min): ditto. (time_hour): ditto. (time_mday): ditto. (time_mon): ditto. (time_year): ditto. (time_wday): ditto. (wday_p): ditto. (time_yday): ditto. (time_isdst): ditto. (time_zone): ditto. (time_utc_offset): ditto. (time_to_a): ditto. (strftimev): ditto. (time_strftime): ditto. (time_mdump): ditto. Modified files: trunk/ChangeLog trunk/time.c Index: time.c =================================================================== --- time.c (revision 23270) +++ time.c (revision 23271) @@ -997,6 +997,19 @@ #define GetTimeval(obj, tobj) \ Data_Get_Struct(obj, struct time_object, tobj) +#define TIME_UTC_P(tobj) ((tobj)->gmt == 1) +#define TIME_SET_UTC(tobj) ((tobj)->gmt = 1) + +#define TIME_LOCALTIME_P(tobj) ((tobj)->gmt == 0) +#define TIME_SET_LOCALTIME(tobj) ((tobj)->gmt = 0) + +#define MAKE_TM(time, tobj) \ + do { \ + if ((tobj)->tm_got == 0) { \ + time_get_tm((time), (tobj)->gmt); \ + } \ + } while (0) + static void time_mark(void *ptr) { @@ -2127,7 +2140,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->gmt) return Qtrue; + if (TIME_UTC_P(tobj)) return Qtrue; return Qfalse; } @@ -2193,7 +2206,7 @@ struct vtm vtm; GetTimeval(time, tobj); - if (!tobj->gmt) { + if (TIME_LOCALTIME_P(tobj)) { if (tobj->tm_got) return time; } @@ -2206,7 +2219,7 @@ tobj->vtm = vtm; tobj->tm_got = 1; - tobj->gmt = 0; + TIME_SET_LOCALTIME(tobj); return time; } @@ -2235,7 +2248,7 @@ struct vtm vtm; GetTimeval(time, tobj); - if (tobj->gmt) { + if (TIME_UTC_P(tobj)) { if (tobj->tm_got) return time; } @@ -2248,7 +2261,7 @@ tobj->vtm = vtm; tobj->tm_got = 1; - tobj->gmt = 1; + TIME_SET_UTC(tobj); return time; } @@ -2343,7 +2356,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->gmt == 1) + if (TIME_UTC_P(tobj)) return strftimev("%Y-%m-%d %H:%M:%S UTC", time); else return strftimev("%Y-%m-%d %H:%M:%S %z", time); @@ -2358,9 +2371,9 @@ result = time_new_timev(rb_cTime, sub(tobj->timev, offset)); else result = time_new_timev(rb_cTime, add(tobj->timev, offset)); - if (tobj->gmt) { + if (TIME_UTC_P(tobj)) { GetTimeval(result, tobj); - tobj->gmt = 1; + TIME_SET_UTC(tobj); } return result; } @@ -2467,9 +2480,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return INT2FIX(tobj->vtm.sec); } @@ -2489,9 +2500,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return INT2FIX(tobj->vtm.min); } @@ -2511,9 +2520,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return INT2FIX(tobj->vtm.hour); } @@ -2535,9 +2542,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return INT2FIX(tobj->vtm.mday); } @@ -2559,9 +2564,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return INT2FIX(tobj->vtm.mon); } @@ -2581,9 +2584,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return tobj->vtm.year; } @@ -2611,18 +2612,14 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return INT2FIX(tobj->vtm.wday); } #define wday_p(n) {\ struct time_object *tobj;\ GetTimeval(time, tobj);\ - if (tobj->tm_got == 0) {\ - time_get_tm(time, tobj->gmt);\ - }\ + MAKE_TM(time, tobj);\ return (tobj->vtm.wday == (n)) ? Qtrue : Qfalse;\ } @@ -2754,9 +2751,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return INT2FIX(tobj->vtm.yday); } @@ -2791,9 +2786,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return tobj->vtm.isdst ? Qtrue : Qfalse; } @@ -2816,11 +2809,9 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); - if (tobj->gmt == 1) { + if (TIME_UTC_P(tobj)) { return rb_str_new2("UTC"); } return rb_str_new2(tobj->vtm.zone); @@ -2847,11 +2838,9 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); - if (tobj->gmt == 1) { + if (TIME_UTC_P(tobj)) { return INT2FIX(0); } else { @@ -2880,9 +2869,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); return rb_ary_new3(10, INT2FIX(tobj->vtm.sec), INT2FIX(tobj->vtm.min), @@ -2942,9 +2929,7 @@ VALUE str; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); len = rb_strftime_alloc(&buf, fmt, &tobj->vtm, tobj->timev, tobj->gmt); str = rb_str_new(buf, len); if (buf != buffer) xfree(buf); @@ -3011,9 +2996,7 @@ VALUE str; GetTimeval(time, tobj); - if (tobj->tm_got == 0) { - time_get_tm(time, tobj->gmt); - } + MAKE_TM(time, tobj); StringValue(format); if (!rb_enc_str_asciicompat_p(format)) { rb_raise(rb_eArgError, "format should have ASCII compatible encoding"); @@ -3091,14 +3074,14 @@ usec = nsec / 1000; nsec = nsec % 1000; - p = 0x1UL << 31 | /* 1 */ - tobj->gmt << 30 | /* 1 */ - (year-1900) << 14 | /* 16 */ - (vtm.mon-1) << 10 | /* 4 */ - vtm.mday << 5 | /* 5 */ - vtm.hour; /* 5 */ - s = vtm.min << 26 | /* 6 */ - vtm.sec << 20 | /* 6 */ + p = 0x1UL << 31 | /* 1 */ + TIME_UTC_P(tobj) << 30 | /* 1 */ + (year-1900) << 14 | /* 16 */ + (vtm.mon-1) << 10 | /* 4 */ + vtm.mday << 5 | /* 5 */ + vtm.hour; /* 5 */ + s = vtm.min << 26 | /* 6 */ + vtm.sec << 20 | /* 6 */ usec; /* 20 */ for (i=0; i<4; i++) { Index: ChangeLog =================================================================== --- ChangeLog (revision 23270) +++ ChangeLog (revision 23271) @@ -1,3 +1,32 @@ +Sat Apr 25 15:21:33 2009 Tanaka Akira <akr@f...> + + * time.c (TIME_UTC_P): new macro.. + (TIME_SET_UTC): ditto. + (TIME_LOCALTIME_P): ditto. + (TIME_SET_LOCALTIME): ditto. + (time_utc_p): use the above macro. + (time_localtime): ditto. + (time_localtime): ditto. + (time_gmtime): ditto. + (time_to_s): ditto. + (time_add): ditto. + (time_sec): ditto. + (time_min): ditto. + (time_hour): ditto. + (time_mday): ditto. + (time_mon): ditto. + (time_year): ditto. + (time_wday): ditto. + (wday_p): ditto. + (time_yday): ditto. + (time_isdst): ditto. + (time_zone): ditto. + (time_utc_offset): ditto. + (time_to_a): ditto. + (strftimev): ditto. + (time_strftime): ditto. + (time_mdump): ditto. + Thu Apr 23 01:30:37 2009 Akinori MUSHA <knu@i...> * ext/zlib/zlib.c (Zlib::GzipFile#path): New method. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/