Граф коммитов

454 Коммитов

Автор SHA1 Сообщение Дата
naruse 97c5a33f7e Time#at receives 3rd argument which specifies the unit of 2nd argument [Feature #13919]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-25 06:20:10 +00:00
eregon 3efe410dd0 time.c (Time#-): Fix documentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 14:54:29 +00:00
nobu 202fbe3046 time.c: preserve marshalled timezone
* time.c (time_add): preserve timezone name restored by Marshal.
  [ruby-core:81892] [Bug #13710]

* time.c (time_mload): reset localtime if having timezone.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-04 04:23:06 +00:00
watson1978 6fcb76ed80 Improve performance of some Time methods
internal.h : add rb_numeric_quo() as internal API.
rational.c : rename numeric_quo() to rb_numeric_quo() as internal API.
time.c (quov): optimize by invoking rb_numeric_quo() to retrieve a value of
    Numeric#quo instead of method dispatching via rb_funcall().

    Time#subsec ->  7 % up
    Time#-      -> 26 % up
    Time#to_f   -> 30 % up
    Time#to_r   ->  7 % up

    [ruby-core:80915] [Bug #13519] [Fix GH-1601]

### Before
         Time#subsec      2.024M (± 8.7%) i/s -     10.062M in   5.009762s
              Time#-      5.049M (± 4.7%) i/s -     25.186M in   5.002379s
           Time#to_f      5.625M (± 4.2%) i/s -     28.066M in   5.000749s
           Time#to_r      1.880M (± 9.7%) i/s -      9.361M in   5.027527s

### After
         Time#subsec      2.155M (± 9.7%) i/s -     10.724M in   5.022579s
              Time#-      6.362M (± 2.0%) i/s -     31.824M in   5.004625s
           Time#to_f      7.287M (± 4.8%) i/s -     36.402M in   5.010983s
           Time#to_r      2.020M (± 9.4%) i/s -     10.059M in   5.021852s

### Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "Time#subsec" do |t|
    time = Time.now
    t.times { time.subsec }
  end

  x.report "Time#-" do |t|
    time1 = Time.now
    time2 = Time.now
    t.times { time1 - time2 }
  end

  x.report "Time#to_f" do |t|
    time = Time.now
    t.times { time.to_f }
  end

  x.report "Time#to_r" do |t|
    time = Time.now
    t.times { time.to_r }
  end
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-27 05:41:00 +00:00
watson1978 c208d15ff7 Improve Time#+ & Time#- performance
* time.c (wadd): use internal addv() function to calculate internal value in
    Time object. On 64-bit machine, Time object might have Fixnum object
    internally by default and addv() can calculate Fixnum objects directly.

* time.c (wsub): use internal subv() function due the same reason in above.

    Time#+ & Time#- will be faster around 15%.

    [ruby-dev:50036] [Bug #13357] [Fix GH-1547]

### Before
             user     system      total        real
Time#+   0.820000   0.000000   0.820000 (  0.818081)
Time#-   0.810000   0.000000   0.810000 (  0.813835)

### After
             user     system      total        real
Time#+   0.710000   0.000000   0.710000 (  0.710241)
Time#-   0.710000   0.010000   0.720000 (  0.714151)

### Test code
require 'benchmark'

Benchmark.bmbm do |x|

  x.report "Time#+" do
    t = Time.now
    2000000.times do
      t + 1
    end
  end

  x.report "Time#-" do
    t = Time.now
    2000000.times do
      t - 1
    end
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-21 03:36:31 +00:00
watson1978 92ea637c62 Improve Time#<=> performance
* time.c (wcmp): use internal cmp() function for comparing internal Fixnum value
    in Time objects. On 64-bit machine, Time object might have Fixnum object
    internally by default and cmp() can compare the Fixnum objects directly.

    Time#<=> will be faster around 60% on 64-bit machine.

* time.c (cmp): add optimized path for comparing internal Bignum value by using
    rb_big_cmp() API. On 32-bit machine, Time object might have Bignum object
    internally by default.

    Time#<=> will be faster around 50% on 32-bit machine.

    [ruby-dev:50034] [Bug #13354] [Fix GH-1546]

### Before
             user     system      total        real
Fixnum   1.410000   0.000000   1.410000 (  1.407848)
Bignum   1.550000   0.000000   1.550000 (  1.549145)

### After
             user     system      total        real
Fixnum   0.880000   0.000000   0.880000 (  0.886662)
Bignum   1.050000   0.000000   1.050000 (  1.047994)

### Test code
require 'benchmark'

Benchmark.bmbm do |x|

  x.report "Fixnum" do
    t1 = Time.now
    t2 = Time.now
    10000000.times do
      t1 <=> t2
    end
  end

  x.report "Bignum" do
    t1 = Time.at(2 ** 64)
    t2 = Time.at(2 ** 64 + 1)
    10000000.times do
      t1 <=> t2
    end
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-21 03:36:30 +00:00
mame fd6dd50f95 time.c: avoid taking a pointer to a member of packed struct
clang 4.0.0 emitted a warning: "taking address of packed member
'subsecx' of class or structure 'vtm' may result in an unaligned
pointer value [-Waddress-of-packed-member]".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-04 13:42:47 +00:00
nobu 2cb399af44 time.c: rename div as divv
* time.c (divv): add suffix to get rid of the name in C standard
  library, and others together.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-11 02:40:14 +00:00
normal c68ec6f147 time.c: use predefined IDs
This reduces rb_intern calls during startup and shortens code.

* time.c: include id.h for predefined IDs
  (id_mul, id_eq, id_ne, id_cmp): remove static variables
  (eq): replace id_eq with idEq
  (cmp, wcmp): replace id_cmp with idCmp
  (weq): replace id_eq with idEq
  (time_timespec): replace id_mul with '*'
  (Init_Time): remove rb_intern calls for removed variables
* common.mk (time.$(OBJEXT)): add depend on id.h

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-10 18:16:58 +00:00
normal 5d3fac0db9 time.c: Improve Time#to_i performance
Time#to_i will be faster around 80% (on 64-bit platforms).

* Before
       user     system      total        real
   2.840000   0.000000   2.840000 (  2.847238)

* After
       user     system      total        real
   1.600000   0.000000   1.600000 (  1.598911)

* Test code
require 'benchmark'

Benchmark.bmbm do |x|
  x.report do
    t = Time.now
    20000000.times do
      t.to_i
    end
  end
end

* time.c (_div): new function avoid rb_funcall
  (div): replace with new _div function
  [ruby-core:80636] [Bug #13418]
  Thanks to Watson <watson1978@gmail.com> for the patch.

From: Watson <watson1978@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-10 18:08:16 +00:00
normal 9b69e9fafc time.c (time_strftime): avoid garbage in common case
strftime format strings which are dynamically-generated will benefit
from avoiding garbage, here.

* time.c (time_strftime): use rb_str_tmp_frozen_{acquire,release}
* test/ruby/test_time.rb (test_strftime_no_hidden_garbage): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-31 02:18:58 +00:00
nobu 44a4d7b057 time.c: fix type of usec2subsecx
* time.c (usec2subsecx): fix return type, which is a numeric
  object but not a long int.  [ruby-dev:49912] [Bug #13066]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-24 12:21:52 +00:00
nobu 4e41d5dedd time.c: remove debug code
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-24 12:19:23 +00:00
nobu 65a884ebad time.c: fix typo in value_insane_p
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-24 11:56:12 +00:00
nobu 11e386cf6c time.c: inquire suspicious values
* time.c (time_arg): dump sec and subsec arguments if subsecx is
  insane.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-23 00:05:40 +00:00
nobu bd2e1034d5 time.c: inquire suspicious values
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-22 22:34:18 +00:00
nobu edaf4500f8 time.c: debug print
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 13:46:46 +00:00
nobu 5518b5c21a time.c: refine num_exact error message
* time.c (num_exact): show the original argument when conversion
  failed, instead of intermediate nil.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 12:06:40 +00:00
nobu 33e8eef020 time.c: use RB_TYPE_P
* time.c (time_timespec): use RB_TYPE_P instead of switching by
  TYPE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 12:05:41 +00:00
nobu 5064e9201a time.c: refine error message
* time.c (validate_vtm): separate validation failure messages for
  each members.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-19 08:36:21 +00:00
akr a03411b63e fix vtm_add_offset yday on last day of year.
* time.c (vtm_add_offset): Fix yday on last day of year.
  [ruby-core:72878] [Bug #11994] Fixed by Andrew White.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 14:59:51 +00:00
usa 774442d27f * time.c (time_arg): guard for mswin64 CI.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-12 15:16:09 +00:00
akr 577de1e93d replace fixnum by integer in documents.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08 04:57:49 +00:00
usa a260f093be * time.c (obj2subsecx): subsec might be GC'ed. try to get rid of SEGV on mswin
CI.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-06 01:21:54 +00:00
usa 8b9f9274c6 * time.c (time_arg): revert r55688 beause it had no effect. retry...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-15 21:39:57 +00:00
usa 363c90853e * time.c (time_arg): it seems that this function sometimes causes SEGV
on mswin CI, then force to prevent `vtm->subsecx` from GC.  this is
  experimental.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-15 06:35:37 +00:00
naruse 173005bb6f * time.c: define _DEFAULT_SOURCE because glibc 2.20 depracates
_BSD_SOURCE.
  https://sourceware.org/glibc/wiki/Release/2.20

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54802 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 16:15:21 +00:00
nobu 5fd589287d time.c: add example [ci skip]
* time.c (time_asctime): [DOC] add ctime example, not only
  asctime.  [ruby-core:75126] [Bug #12310]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-22 11:34:05 +00:00
nobu 5396d8a1ab strftime.c: format in String
* strftime.c (rb_strftime_with_timespec): append formatted results
  to the given string with expanding, and also deal with NUL chars.
* strftime.c (rb_strftime, rb_strftime_timespec): return formatted
  string, not the length put in the given buffer.
* time.c (rb_strftime_alloc): no longer needs to retry with
  reallocating buffers.
* time.c (time_strftime): no longer needs to split by NUL chars.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-23 11:57:01 +00:00
usa 15af93fcc8 * time.c (wmul): wrong condition.
fixed many test failures on 32bit and LLP64 platforms.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-22 02:41:24 +00:00
usa 6957898ad0 * time.c (wdiv, wmod): wdivmod0() assumes the 3rd and the 4th arguments
are valid pointers.
  maybe checking them in wdivmod0() is better manner, but I guess that
  passing real dummy pointers may be faster than checking and branching
  in wdivmod0().
  this commit fixes SEGV on 32bit and LLP64 platforms.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-22 01:37:01 +00:00
usa 0dbbcdb6bb * time.c (divmodv): void function never returns any value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-22 01:24:55 +00:00
naruse 520650798c fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 19:14:27 +00:00
naruse 03d0501f51 * time.c (MUL_OVERFLOW_FIXWV_P): defined for FIXWV.
* time.c (wmul): use MUL_OVERFLOW_FIXWV_P and only switch.

* time.c (wmul): use mul which has Fixnum optimization.

* time.c (rb_time_magnify): If WIDEVALUE_IS_WIDER, wmul() has the same
  optimized logic, else mul() has also the similar logic for Fixnum.

* time.c (rb_time_unmagnify): almost ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 18:57:30 +00:00
naruse 74d7b281d3 fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 18:57:25 +00:00
naruse 849bbc6566 * time.c (divmodv): add the case both arguments are Fixnum.
* time.c (wquo): use quo which has Fixnum optimization.

* time.c (wdivmod0): added for WIDEVALUE_IS_WIDER.

* time.c (wdivmod): use wdivmod0 and divmodv.
  divmodv has Fixnum optimization.

* time.c (wdiv): use wdivmod0 and div to avoid the use of divmodv which
  calls id_quo whose return value is array.

* time.c (wmod): use wdivmod0 and mod to avoid the use of divmodv which
  calls id_quo whose return value is array.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 18:19:15 +00:00
naruse 51c4ffa45b * internal.h (rb_fix_divmod_fix): like r54213, use FIX2NUM only if
x == FIXNUM_MIN && y == -1. This must be a rare case and it is
  expected compiler to handle well.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:36:03 +00:00
nobu 2118eccc77 time.c (quo): fix missing return
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:31:30 +00:00
naruse 654788793d fix commit miss
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:21:12 +00:00
naruse f5715289ac * time.c (mod): Add Fixnum case.
* time.c (quo): c can be Fixnum except a == FIXNUM_MIN && b == -1.
  Such case can be optimized out because quo()'s argument is constant.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:17:45 +00:00
nobu ce5ba9197d time.c (mul): fix missing return.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 11:26:17 +00:00
naruse 148f1b9d57 * internal.h (DLONG): defined if long is 32bit (and LONG_LONG is 64bit;
but LONG_LONG is always defined as 64bit), or there's int128_t.

* internal.h (DL2NUM): defined if DLONG is defined.

* internal.h (rb_fix_mul_fix): defined for `Fixnum * Fixnum`.

* insns.def (opt_mul): use rb_fix_mul_fix().

* numeric.c (fix_mul): ditto.

* time.c (mul): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 11:10:43 +00:00
naruse cb390bef8a * time.c (add): remove FIXABLE() which is in LONG2NUM().
* time.c (sub): ditto.

* time.c (mul): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 09:47:20 +00:00
naruse 4eb908d21a * time.c (LOCALTIME): organize #ifdefs.
* time.c (GMTIME): define only ifndef HAVE_STRUCT_TM_TM_GMTOFF.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 19:06:33 +00:00
naruse 9a8b21446e * configure.in (rb_cv_member_struct_tm_tm_gmtoff): For Linux (glibc)
define _BSD_SOURCE for time.h to define struct tm.tm_gmtoff.

* time.c: define _BSD_SOURCE at the top.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 19:06:32 +00:00
hsbt 8709f42ff2 * time.c: Minor typo in Time#dst? documentation.
[ci skip][fix GH-1290]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-15 00:56:45 +00:00
naruse 911b1c6b06 * time.c (rb_time_timespec_new): swap utc and localtime
to generate gmt flag by INT_MAX - gmtoff.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-10 05:36:47 +00:00
naruse f1df08e76d * time.c (rb_timespec_now): added.
* time.c (rb_time_timespec_new): added.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-10 02:59:47 +00:00
naruse 2b15d16987 fix comment: tobj->gmt is 0:localtime 1:utc 2:fixoff 3:init
see also TIME_UTC_P and TIME_LOCALTIME_P

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-09 17:18:35 +00:00
nobu 4191a6b90d preserve encodings in error messages
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-28 02:40:46 +00:00