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

924 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 2d6f8db3d6 add spaces [ci skip] 2020-06-29 11:05:41 +09:00
卜部昌平 86c869fb59 ary_ensure_room_for_unshift: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 2e8d8d10f2 rb_ary_behead: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Burdette Lamar 5e860ed4c1
[ci skip] Enhanced RDoc for Array (#3252)
Methods:

    map/collect
    map!/collect!
    values_at
    select/filter
    select!/filter!
2020-06-24 13:31:42 -05:00
Burdette Lamar dc351ff984
[ci skip] Enhanced RDoc for Array (#3237)
Methods:

    #rotate!
    #rotate
    #sort!
    #sort
    #bsearch
    #bsearch_index
2020-06-23 08:58:26 -05:00
Burdette Lamar a5bc0b8f8c
[ci skip] Enhanced RDoc for Array (#3224)
Methods:

    #to_a
    #to_h
    #to_ary
    #reverse!
    #reverse
2020-06-18 08:30:04 -05:00
Nobuyoshi Nakada b8804010fb
Remove non-US-ASCII characters [ci skip] 2020-06-14 23:59:48 +09:00
Burdette Lamar 8b58f1d8c7
[ci skip] Enhanced RDoc for Array (#3219)
Methods:

    #join
    #inspect/#to_s
    #to_a
2020-06-13 09:14:17 -05:00
Burdette Lamar eabdad5e2f
[ci skip] Enhanced Rdoc for Array (#3216)
Methods:

    #insert
    #each
    #each_index
    #reverse_each
    #length
    #empty?
2020-06-12 11:32:31 -05:00
Burdette Lamar eb5ecc2ea8
Enhanced Rdoc for Array#rindex and Array#[]= (#3204)
* Enhanced Rdoc for Array#rindex and Array#[]=

* Enhanced Rdoc for Array#rindex and Array#[]=
2020-06-11 10:55:11 -05:00
Burdette Lamar 8d4b259408
Enhanced Rdoc for Array#fetch and Array#index (#3202)
* Enhanced Rdoc for Array#fetch and Array#index
* Couple of tweaks (per review) in Rdoc for Hash
2020-06-10 06:45:29 -05:00
Burdette Lamar b85b866300
Enhanced Rdoc for Array (#3193)
Methods:

    #freeze
    #<<
    #push
    #pop
    #shift
    #unshift
    #slice
    #at
    #first
    #last
2020-06-09 13:57:41 -05:00
Masataka Pocke Kuwabara a3f498e44c
Fix max, min, minmax documentation (#3131)
They only need that all objects implement <=>,
but the documentation said it needs Comparable.
2020-05-26 23:48:46 -07:00
Kenta Murata f4f157fc81
Suppress warnings no inline ruby debug (#3107)
* Suppress unused warnings occurred due to -fno-inline

* Suppress warning occurred due to RUBY_DEBUG=1
2020-05-22 13:49:08 +09:00
S-H-GAMELINKS 1f063abb4c add static modifier to rb_ary_aref2 func 2020-05-19 15:22:53 +09:00
Burdette Lamar 24739c62e5
[ci skip] Rdoc enhancements for Array (#3063)
* Per @nobu review

* Rdoc enhancements for Array

* Responses to review
2020-05-15 14:12:40 -07:00
卜部昌平 32623150cd reroute redefinition of NDEBUG
NDEBUG can be defined via a command-line argument.  Should take care of
such situations.
2020-04-21 13:07:19 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada 5b287481be
Removed non-RUBY_INTEGER_UNIFICATION code 2020-03-21 16:59:55 +09:00
卜部昌平 2325017477 fix compile error w/ -DUSE_TRANSIENT_HEAP=0
rb_transient_heap_managed_ptr_p is available only when USE_TRANSIENT_HEAP.
Need #if guards.
2020-03-04 12:30:42 +09:00
Chelsea Corvus (Battell) 672213ef1c
Document that Array#index and find_index are aliases [ci skip] 2020-02-25 13:43:17 -05:00
Nobuyoshi Nakada d4e1d4e94e
Moved Array#sample to rbinc 2020-01-26 19:45:58 +09:00
Nobuyoshi Nakada 29eb1b1602
Moved Array#shuffle and Array#shuffle! to rbinc 2020-01-26 19:40:34 +09:00
Nobuyoshi Nakada 0c436bbfbf
Recheck array length after `to_str` conversion
https://hackerone.com/reports/244787
2020-01-25 14:06:38 +09:00
Nobuyoshi Nakada 2b2821acd3
Recheck elements type after `to_str` conversion
https://hackerone.com/reports/244786
2020-01-25 13:57:33 +09:00
Ary Borenszweig e5c441a4a2 Optimize Array#rotate!(n) for n = 1 and n = -1
For the most common cases of `rotate!` one place to the right or to the
left, instead of doing some reversals of the array we just keep a single
value in a temporary value, use memmove and then put the temporary
value where it should be.
2019-12-29 13:12:42 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
卜部昌平 0e8219f591 make functions static
These functions are used from within a compilation unit so we can
make them static, for better binary size.  This changeset reduces
the size of generated ruby binary from 26,590,128 bytes to
26,584,472 bytes on my macihne.
2019-11-19 12:36:19 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Ben Woosley bb71a128eb Prefer st_is_member over st_lookup with 0
The st_is_member DEFINE has simpler semantics, for more readable code.
2019-10-09 23:46:50 +09:00
Watson 2d001003e4 Improve performance of Array#sum with float elements (#1555)
The declaration of local variable in loop, it will initialize local variable for each run of the loop with clang generated code.
So, it shouldn't declare the local variable in heavy loop.

Array#sum with float elements will be faster around 30%.

* Before
       user     system      total        real
   3.320000   0.010000   3.330000 (  3.336088)

* After
       user     system      total        real
   2.590000   0.010000   2.600000 (  2.602399)

* Test code
require 'benchmark'

Benchmark.bmbm do |x|
  ary = []
  10000.times { ary << Random.rand }

  x.report do
    50000.times do
      ary.sum
    end
  end

end
2019-10-09 12:25:07 +09:00
Prajjwal Singh c8542ab484 Add: Array#intersection method 2019-10-07 15:59:12 +09:00
Yusuke Endoh 113bef6976 array.c (rb_mem_clear): remove "register" from arguments
to suppress the following warning:

```
compiling cxxanyargs.cpp
In file included from cxxanyargs.cpp:1:
In file included from ../../.././include/ruby/ruby.h:2150:
../../.././include/ruby/intern.h:56:19: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
void rb_mem_clear(register VALUE*, register long);
                  ^~~~~~~~~
../../.././include/ruby/intern.h:56:36: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
void rb_mem_clear(register VALUE*, register long);
                                   ^~~~~~~~~
```
2019-10-04 16:07:46 +09:00
Benoit Daloze ce477089f6 [DOC] Fix typos in Array#{to_s,inspect} doc [ci skip] 2019-09-29 11:04:28 +02:00
Nobuyoshi Nakada e2d97cffe5
[DOC] stated that Array#to_s calls #inspect [ci skip]
[ruby-list:50826]
2019-09-29 17:28:58 +09:00
Dylan Thacker-Smith a1fda16b23 Optimize Array#flatten and flatten! for already flattened arrays (#2495)
* Optimize Array#flatten and flatten! for already flattened arrays
* Add benchmark for Array#flatten and Array#flatten!

[Bug #16119]
2019-09-28 01:24:24 +09:00
Koichi Sasada 6d578164f5 check `ARY_SHARED_ROOT_P()`.
ARY_SHARED_ROOT_P(ary) is true, ARY_HEAP_CAPA(ary) should not
be called.
2019-09-25 17:12:55 +09:00
Koichi Sasada 3deeb3fd91 introduce `obj_ary_extracapa`.
Introduce a new debug counter `obj_ary_extracapa` which counts
arrays which are `len < capa`.
2019-09-25 17:01:54 +09:00
Nobuyoshi Nakada 422ae594d9
Fixed memory leak
* array.c (flatten): fix a memory leak in the case of an exception
  at conversion of an element to Array.
2019-09-20 10:49:49 +09:00
Kenichi Kamiya 9118cb242b Fix typos 2019-09-18 17:29:30 +09:00
Jeremy Evans 1994adf938 Make Array#uniq return subclass instance if called on subclass instance
Previously, Array#uniq would return subclass instance if the
length of the array were 2 or greater, and would return Array
instance if the length of the array were 0 or 1.

Fixes [Bug #7768]
2019-09-02 13:42:31 -07:00
Olivier Lacan 7c46aa6911 Avoid confusion in Array#- and Array#difference docs (#2070)
My previous attempt to correct #2068 apparently failed and the confusing
wording ("instances") was merged into trunk instead.

This should address any potential confusion.
2019-08-16 00:42:17 +09:00
John Hawthorn 9d298b9dab
Allow Array#join to allocate smaller strings
rb_str_buf_new always allocates at least 127 bytes of capacity, even
when less is requested.

    > ObjectSpace.dump(%w[a b c].join)
    {"address":"0x7f935f06ebf0", "type":"STRING", "class":"0x7f935d8b7bb0", "bytesize":3, "capacity":127, "value":"abc", "encoding":"UTF-8", "memsize":168, "flags":{"wb_protected":true}}

Instead, by using rb_str_new and then setting the length to 0, we can
allocate the exact amount of memory needed, without extra capacity.

    > ObjectSpace.dump(%w[a b c].join)
    {"address":"0x7f903fcab530", "type":"STRING", "class":"0x7f903f8b7988", "embedded":true, "bytesize":3, "value":"abc", "encoding":"UTF-8", "memsize":40, "flags":{"wb_protected":true}}
2019-08-09 16:33:53 -07:00
Yusuke Endoh f82633b6a6 array.c: gc.h is not needed 2019-08-07 22:56:52 +09:00
Kenichi Kamiya 0f601df22c
[Doc] Fix Array#to_h call-seq
Closes: https://github.com/ruby/ruby/pull/2254
2019-08-04 09:20:56 +09:00
Kenichi Kamiya 84829392f5
[Doc] Fix Array#difference call-seq
Closes: https://github.com/ruby/ruby/pull/2255
2019-08-04 09:20:29 +09:00
Yusuke Endoh 77bb79b8cf array.c: factor out a complex condition of assert
ARY_SHARED_P and ARY_EMBED_P included:

   assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)),

The two predicate macros are used in many other assert conditions,
which caused memory bloat during C compilation.
This change factors out the assertion above to a function.
Now gcc consumes 160 MB instead of 250 MB to compile array.c.
2019-07-20 09:08:34 +09:00
Yusuke Endoh 0a16ff9f83 array.c: use assert in macro instead of in a function
The old code lost information of lineno.  Now, an assertion error will
output a correct lineno (but now gcc 8 requires 250 MB, unfortunately).
2019-07-19 23:50:30 +09:00
Yusuke Endoh 3e8d4ff3e5 array.c: factor out `assert(RB_TYPE_P(ary, T_ARRAY))` to a function
The assertion blows up gcc 8 by consuming approx. 1.8 GB memory.
This change reduces the amount of memory required to about 200 MB.

A follow-up of ae750799c1.
2019-07-19 23:41:24 +09:00
Koichi Sasada ae750799c1 Use FL_TEST_RAW() to check flags.
FL_TEST() uses FL_ABLE() which test data types. However,
in array.c we don't need to check it (all of them should be
T_ARRAY), so I changed from FL_TEST() to FL_TEST_RAW() which
does not check FL_ABLE(). Instead of FL_ABLE(), add assertion
to check given object is a T_ARRAY object.

For example, rb_ary_free() becomes slim:

with FL_TEST():
0000000000006a30 <rb_ary_free>:
    6a30:       40 f6 c7 07             test   $0x7,%dil
    6a34:       48 8b 07                mov    (%rdi),%rax
    6a37:       75 09                   jne    6a42 <rb_ary_free+0x12>
    6a39:       48 f7 c7 f7 ff ff ff    test   $0xfffffffffffffff7,%rdi
    6a40:       75 1e                   jne    6a60 <rb_ary_free+0x30>
    6a42:       a9 00 00 00 02          test   $0x2000000,%eax
    6a47:       74 07                   je     6a50 <rb_ary_free+0x20>
    6a49:       f3 c3                   repz retq
    6a4b:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)
    6a50:       48 8b 7f 20             mov    0x20(%rdi),%rdi
    6a54:       e9 00 00 00 00          jmpq   6a59 <rb_ary_free+0x29>
    6a59:       0f 1f 80 00 00 00 00    nopl   0x0(%rax)
    6a60:       89 c2                   mov    %eax,%edx
    6a62:       83 e2 1f                and    $0x1f,%edx
    6a65:       83 fa 1b                cmp    $0x1b,%edx
    6a68:       74 d8                   je     6a42 <rb_ary_free+0x12>
    6a6a:       f6 c4 60                test   $0x60,%ah
    6a6d:       74 d3                   je     6a42 <rb_ary_free+0x12>
    6a6f:       eb d8                   jmp    6a49 <rb_ary_free+0x19>```

with FL_TEST_RAW():
0000000000006a30 <rb_ary_free>:
    6a30:       48 f7 07 00 60 00 02    testq  $0x2006000,(%rdi)
    6a37:       74 07                   je     6a40 <rb_ary_free+0x10>
    6a39:       f3 c3                   repz retq
    6a3b:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)
    6a40:       48 8b 7f 20             mov    0x20(%rdi),%rdi
    6a44:       e9 00 00 00 00          jmpq   6a49 <rb_ary_free+0x19>
2019-07-19 14:41:36 +09:00