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

980 Коммитов

Автор SHA1 Сообщение Дата
Burdette Lamar 3b96ad9b54
Enhanced RDoc for Array#fill (#3301)
* Enhanced RDoc for Array#fill

* Update array.c

There's one more at 5072.  I'll get it.

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>

* Update array.c

Co-authored-by: Eric Hodel <drbrain@segment7.net>
2020-07-11 08:01:56 -05:00
Burdette Lamar 9fc25811d5
Enhanced RDoc for Array (#3282)
Methods:

    reject!
    reject
    delete_if
    zip
    transpose
    replace
    clear
2020-07-08 09:27:10 -05:00
Burdette Lamar e8010c7401
Enhanced RDoc for Array (#3276)
*Methods:

    keep_if
    delete
    delete_at
    slice!
2020-07-03 09:49:36 -05:00
卜部昌平 4f2425549a rb_ary_slice_bang: 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
卜部昌平 73f98d25eb ary_join_1: 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
卜部昌平 4dc83eefce rb_ary_aset: 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
卜部昌平 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
git a44ad9a145 * expand tabs. 2019-07-19 13:10:08 +09:00
Koichi Sasada 182ae1407b fix shared array terminology.
Shared arrays created by Array#dup and so on points
a shared_root object to manage lifetime of Array buffer.
However, sometimes shared_root is called only shared so
it is confusing. So I fixed these wording "shared" to "shared_root".

* RArray::heap::aux::shared -> RArray::heap::aux::shared_root
* ARY_SHARED() -> ARY_SHARED_ROOT()
* ARY_SHARED_NUM() -> ARY_SHARED_ROOT_REFCNT()

Also, add some debug_counters to count shared array objects.

* ary_shared_create: shared ary by Array#dup and so on.
* ary_shared: finished in shard.
* ary_shared_root_occupied: shared_root but has only 1 refcnt.
  The number (ary_shared - ary_shared_root_occupied) is meaningful.
2019-07-19 13:07:59 +09:00
Koichi Sasada f6f09cbc76 introduce RUBY_ASSERT_ALWAYS(expr).
RUBY_ASSERT_ALWAYS(expr) ignores NDEBUG (we cannot remove this
assertion).
2019-07-15 10:21:41 +09:00
Jeremy Evans ced640951b Implement Array#minmax
Array#minmax was previous not implemented, so calling #minmax on
array was actually calling Enumerable#minmax.  This is a simple
implementation of #minmax by just calling rb_ary_min and
rb_ary_max, which improves performance significantly.

Fixes [Bug #15929]
2019-07-02 08:07:06 -07:00
Luke Gruber 97b4fe2ff6
array.c: Wrong heap size given to ruby_sized_xfree when freeing shared roots
Fixes [Bug #15953]

Closes: https://github.com/ruby/ruby/pull/2253
2019-06-24 13:34:30 +09:00
Luke Gruber 5a187e26ad array.c add back shared array optimization to ary_ensure_room_for_unshift
Bug fix in commit ec8e5f5aa6 [Bug #15952] disabled an
optimization in this function.

Closes: https://github.com/ruby/ruby/pull/2252
2019-06-23 13:17:41 +09:00
Luke Gruber ec8e5f5aa6
array.c: always check frozenness in Array#unshift. Fixes [Bug #15952]
Closes: https://github.com/ruby/ruby/pull/2251
2019-06-23 08:05:13 +09:00
Luke Gruber c033dc3073
Fix issue with Array#rindex when rb_equal modifies receiver array
Fixes [Bug #15951]

Closes: https://github.com/ruby/ruby/pull/2250
2019-06-23 00:49:24 +09:00
Martin Dürst 7f79a86d8b add comments to mention sort.reverse!
For array.c (Array#sort) and enum.c (Enumerable#sort_by),
add comments mentioning that sort.reverse! / sort_by { ... }.reverse!
can/should be used to reverse the result. [ci skip]
2019-06-13 15:30:03 +09:00
Koichi Sasada 0b9a7b3528 do not use RARRAY_SET() directly in array.c. 2019-05-21 15:02:54 +09:00
Benoit Daloze 87d2a2df1b Improve documentation of Array.try_convert
* Mostly to try the new git repository.
2019-04-27 16:43:28 +02:00
Kazuhiro NISHIYAMA 8c689e216f
Merge branch 'patch-5' of https://github.com/sos4nt/ruby into trunk
[Fix GH-2084]
2019-04-22 22:45:32 +09:00
nobu 3ee0648dc7 io.c: warn non-nil $,
* array.c (rb_ary_join_m): warn use of non-nil $,.

* io.c (rb_output_fs_setter): warn when set to non-nil value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-18 21:56:55 +00:00
ktsj 9738f96fcf Introduce pattern matching [EXPERIMENTAL]
[ruby-core:87945] [Feature #14912]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 06:48:03 +00:00
nobu b9e52ef8b6 Adjusted styles
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 12:43:33 +00:00
kazu 25c1fd3b90 Reverting all commits from r67479 to r67496 because of CI failures
Because hard to specify commits related to r67479 only.
So please commit again.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 09:15:21 +00:00
nobu 5ae753dfa3 Adjusted styles
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 06:44:41 +00:00
kazu ddc5839005 Fix a typo [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-31 14:46:25 +00:00
nobu 638c968582 array.c: [DOC] remove unnecessary markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-21 12:01:36 +00:00
Stefan Schüßler e19e5d2409
Fix return value name in docs for Array#union
Throughout the docs, `new_ary` is used to indicate a new array, whereas `ary` refers to the receiver.
2019-02-18 12:44:01 +01:00
nobu 10d85b19da Clarify Array#- and Array#difference documentation
Currently we are not explicit enough regarding the potentially confusing
behavior of `Array#-` and `Array#difference` when it comes to duplicate items
within receiver arrays.

Although the original documentation for these methods does use an array with
multiple instance of the same integers, the explanation for the behavior is
actually imprecise.

> removing any items that also appear in +other_ary+

Not only does `Array#-` remove any items that also appear in `other_ary` but
it also remove any instance of any item in `other_ary`.

One may expect `Array#-` to behave like mathematical subtraction or difference
when it doesn't. One could be forgiven to expect the following behavior:

```ruby
[1,1,2,2,3,3,4,4] - [1,2,3,4]
=> [1,2,3,4]
```

In reality this is the result:

```ruby
[1,1,2,2,3,3,4,4] - [1,2,3,4]
=> []
```

I hope that I've prevented this potential confusion with the clarifications
in this change. I can offer this as evidence of likeliness for confusion:
https://twitter.com/olivierlacan/status/1084930269533085696

I'll freely admit I was surprised by this behavior myself since I needed to
obtain an Array with only one instance of each item in the argument array
removed.

[Fix GH-2068] [ci skip]

From: Olivier Lacan <hi@olivierlacan.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-15 13:52:38 +00:00
nobu 78d6e33702 Fix styles [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09 13:58:49 +00:00
tenderlove 79c150f8a5 Mark array as "going to be modified" in `Array#reject!`
Before this patch, if `reject!` is called on a shared array it can
mutate the shared array rather than a copy.  This patch marks the array
as "going to be modified" so that the shared source array isn't
mutated.

[Bug #15479] [ruby-core:90781]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-08 19:22:05 +00:00
ko1 4c9f3ce7b1 fix marking T_NONE object bug.
* array.c (rb_ary_splice): do not use RARRAY_PTR() here because it can cause
  GC because of rb_ary_detransient(). Here ary can contain T_NONE object
  because of increasing capacity and not initialized yet.

  error log: http://ci.rvm.jp/results/trunk-test@ruby-sky1/1557174


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-23 14:58:41 +00:00
ko1 e4c79d0d10 rename li_table->ar_table (and related names).
* internal.h: rename the following names:
  * li_table -> ar_table. "li" means linear (from linear search),
    but we use the word "array" (from data layout).
  * RHASH_ARRAY -> RHASH_AR_TABLE. AR_TABLE is more clear.
  * rb_hash_array_* -> rb_hash_ar_table_*.
  * RHASH_TABLE_P() -> RHASH_ST_TABLE_P(). more clear.
  * RHASH_CLEAR() -> RHASH_ST_CLEAR().

* hash.c: rename "linear_" prefix functions to "ar_" prefix.

* hash.c (linear_init_table): rename to ar_alloc_table.

* debug_counter.h: rename obj_hash_array to obj_hash_ar.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-14 01:10:15 +00:00
nobu 78be4478d1 implement Array-specific #all?, #none?, #one?
Before this patch Array#all? was not implemented in Array class
and alternatively Enumerable#all? was used, while #any? has its
own method entry in Array class.  Similarly, Array#none? and #one?
also lacks its own implementation.
This patch provides Array-specific implementations for above three
methods to enable faster method lookup.

[Fix GH-2041]

From: Koji Onishi <fursich0@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05 04:25:44 +00:00
nobu 09ef29a78f Prefer rb_check_arity when 0 or 1 arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05 01:09:44 +00:00
nobu c28c20ee88 Fix error message
* array.c (ary_take_first_or_last): expected optional argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04 09:16:49 +00:00
nobu 4b85e88174 Prefer rb_check_arity when 0 or 1 arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04 02:24:15 +00:00
svn 888cdf605c * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 12:36:47 +00:00
ko1 5e11de6585 make `RARRAY_PTR_USE` more conservertive.
* include/ruby/ruby.h: de-transient at
  `RARRAY_PTR_USE` and `RARRAY_PTR_USE_START`.
  Introduce `RARRAY_PTR_USE_TRANSIENT` and
  `RARRAY_PTR_USE_START_TRANSIENT` if you don't want to
  de-transient an array. Generally, it is difficult
  so C-extension writers should not use them.

* array.c: use `RARRAY_PTR_USE_TRANSIENT` if possible.

* hash.c: ditto.

* enum.c (enum_sort_by): remove `rb_ary_transient_heap_evacuate()`
  because `RARRAY_PTR_USE` do de-transient.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 12:36:39 +00:00
tenderlove d46cd60f3c Use a shared array for the `duparray` instruction
In this example code:

```ruby
def foo
  [1, 2, 3, 4]
end
```

The array literal uses a `duparray` instruction. Before this patch,
`rb_ary_resurrect` would malloc and memcpy a new array buffer.  This
patch changes `rb_ary_resurrect` to use `ary_make_partial` so that the
new array object shares the underlying buffer with the array stored in
the instruction sequences.

Before this patch, the new array object is not shared:

```
$ ruby -r objspace -e'p ObjectSpace.dump([1, 2, 3, 4])'
"{\"address\":\"0x7fa2718372d0\", \"type\":\"ARRAY\", \"class\":\"0x7fa26f8b0010\", \"length\":4, \"memsize\":72, \"flags\":{\"wb_protected\":true}}\n"
```

After this patch:

```
$ ./ruby -r objspace -e'p ObjectSpace.dump([1, 2, 3, 4])'
"{\"address\":\"0x7f9a76883638\", \"type\":\"ARRAY\", \"class\":\"0x7f9a758af900\", \"length\":4, \"shared\":true, \"references\":[\"0x7f9a768837c8\"], \"memsize\":40, \"flags\":{\"wb_protected\":true}}\n"
```

[Feature #15289] [ruby-core:90097]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29 20:39:51 +00:00
svn 31649a24cf * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65924 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22 09:18:43 +00:00
nobu b309975a91 Revert r63030
* array.c (rb_ary_collect): no longer splat sole array for lambda.
  [ruby-core:89734] [Bug #15285]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65923 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22 09:18:40 +00:00
shyouhei 6bdca5d85e array.c: avoid (VALUE)--
This args[1]-- overflows when it is zero.  Should do that only
when we can say it is nonzero.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-19 06:48:09 +00:00
stomar 139d9d819c array.c: [DOC] add docs for Array#{filter,filter!}
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04 11:40:32 +00:00
stomar bd20f031db array.c: [DOC] improve Array#{select,select!,keep_if} docs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04 11:39:28 +00:00
ko1 c39797e872 introduce USE_TRANSIENT_HEAP to enable/disable theap.
* include/ruby/ruby.h: intrdocue `USE_TRANSIENT_HEAP` macro
  to enable/disable transient heap.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-01 08:53:44 +00:00
svn d4f1187d31 * remove trailing spaces, expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:12:12 +00:00
ko1 8f675cdd00 support theap for T_HASH. [Feature #14989]
* hash.c, internal.h: support theap for small Hash.
  Introduce RHASH_ARRAY (li_table) besides st_table and small Hash
  (<=8 entries) are managed by an array data structure.
  This array data can be managed by theap.
  If st_table is needed, then converting array data to st_table data.

  For st_table using code, we prepare "stlike" APIs which accepts hash value
  and are very similar to st_ APIs.

  This work is based on the GSoC achievement
  by tacinight <tacingiht@gmail.com> and refined by ko1.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:11:51 +00:00
svn 437392232a * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:54:13 +00:00
ko1 312b105d0e introduce TransientHeap. [Bug #14858]
* transient_heap.c, transient_heap.h: implement TransientHeap (theap).
  theap is designed for Ruby's object system. theap is like Eden heap
  on generational GC terminology. theap allocation is very fast because
  it only needs to bump up pointer and deallocation is also fast because
  we don't do anything. However we need to evacuate (Copy GC terminology)
  if theap memory is long-lived. Evacuation logic is needed for each type.

  See [Bug #14858] for details.

* array.c: Now, theap for T_ARRAY is supported.

  ary_heap_alloc() tries to allocate memory area from theap. If this trial
  sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on.
  We don't need to free theap ptr.

* ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that
  if ary is allocated at theap, force evacuation to malloc'ed memory.
  It makes programs slow, but very compatible with current code because
  theap memory can be evacuated (theap memory will be recycled).

  If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT()
  instead of RARRAY_CONST_PTR(). If you can't understand when evacuation
  will occur, use RARRAY_CONST_PTR().

(re-commit of r65444)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:53:56 +00:00
svn 69b8ffcd5b * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:02:12 +00:00
ko1 7d359f9b69 revert r65444 and r65446 because of commit miss
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:01:55 +00:00