ruby-changes:64689
From: Nobuyoshi <ko1@a...>
Date: Thu, 31 Dec 2020 18:20:55 +0900 (JST)
Subject: [ruby-changes:64689] 9101597d05 (master): Moved Time.now to builtin
https://git.ruby-lang.org/ruby.git/commit/?id=9101597d05 From 9101597d05ef645949bab3a210d8fa5e61de26e3 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 30 Dec 2020 01:54:57 +0900 Subject: Moved Time.now to builtin diff --git a/time.c b/time.c index 785a584..b3cd300 100644 --- a/time.c +++ b/time.c @@ -2741,24 +2741,12 @@ get_tmopt(VALUE opts, VALUE vals[TMOPT_MAX_]) https://github.com/ruby/ruby/blob/trunk/time.c#L2741 return true; } -/* - * call-seq: - * Time.now -> time - * - * Creates a new Time object for the current time. - * This is same as Time.new without arguments. - * - * Time.now #=> 2009-06-24 12:39:54 +0900 - */ - static VALUE -time_s_now(int argc, VALUE *argv, VALUE klass) +time_s_now(rb_execution_context_t *ec, VALUE klass, VALUE zone) { - VALUE vals[TMOPT_MAX_], opts, t, zone = Qundef; - rb_scan_args(argc, argv, ":", &opts); - if (get_tmopt(opts, vals)) zone = vals[TMOPT_IN]; + VALUE t; t = rb_class_new_instance(0, NULL, klass); - if (zone != Qundef) { + if (!NIL_P(zone)) { time_zonelocal(t, zone); } return t; @@ -5859,7 +5847,6 @@ Init_Time(void) https://github.com/ruby/ruby/blob/trunk/time.c#L5847 rb_include_module(rb_cTime, rb_mComparable); rb_define_alloc_func(rb_cTime, time_s_alloc); - rb_define_singleton_method(rb_cTime, "now", time_s_now, -1); rb_define_singleton_method(rb_cTime, "at", time_s_at, -1); rb_define_singleton_method(rb_cTime, "utc", time_s_mkutc, -1); rb_define_singleton_method(rb_cTime, "gm", time_s_mkutc, -1); diff --git a/timev.rb b/timev.rb index 792d600..8f20d66 100644 --- a/timev.rb +++ b/timev.rb @@ -1 +1,11 @@ # +# call-seq: +# Time.now -> time +# +# Creates a new Time object for the current time. +# This is same as Time.new without arguments. +# +# Time.now #=> 2009-06-24 12:39:54 +0900 +def Time.now(in: nil) + __builtin.time_s_now(__builtin.arg!(:in)) +end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/