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

991 Коммитов

Автор SHA1 Сообщение Дата
Kenichi Kamiya 92545977de
[Doc] Add Hash#value? into call-seq (#4293) 2021-04-15 11:14:43 +09:00
Kenichi Kamiya 522d4cd32f
Force recycle intermediate collection in Hash#transform_keys! [Bug #17735]
* Force recycle intermediate hash

* Force recycle intermediate array too

https://github.com/ruby/ruby/pull/4329#issuecomment-808840718
2021-03-28 14:09:52 +09:00
Nobuyoshi Nakada fb6ebe55d9
Hide an intermediate array 2021-03-28 09:48:45 +09:00
Nobuyoshi Nakada 5e5fb72f99
Clear an intermediate hash [Bug #17735] 2021-03-28 09:42:26 +09:00
Kenichi Kamiya 31e0382723
Keep non evaluated keys in `Hash#transform_keys!` [Bug #17735] 2021-03-28 09:14:57 +09:00
Kenichi Kamiya 5b272a6453 [Doc] Fix a typo around Hash#compare_by_identity 2021-03-22 08:16:19 -04:00
Kenichi Kamiya 7d3fdfb27d
Hash#transform_values! ensures receiver modifiable in block [Bug #17736] 2021-03-22 14:10:52 +09:00
Nobuyoshi Nakada d36ac283d1
Ensure the receiver hash modifiable before updating [Bug #17736]
Close https://github.com/ruby/ruby/pull/4298
2021-03-21 10:07:24 +09:00
Nobuyoshi Nakada 298edfa4a2
Refactor hash aset callback 2021-03-21 00:11:08 +09:00
Nobuyoshi Nakada 0b6554e65b
Refactor hash update callbacks 2021-03-20 23:42:15 +09:00
Kenichi Kamiya 7954bb056b Some Hash destructive methods ensure the receiver modifiable [Bug #17736]
refs:

* https://bugs.ruby-lang.org/issues/17736
* https://github.com/ruby/ruby/pull/4296

This commit aims to cover following methods

* Hash#select!
* Hash#filter!
* Hash#keep_if
* Hash#reject!
* Hash#delete_if

I think these are not all.

---

* Ensure the receiver is modifiable or not
* Assert the receiver is not modified
2021-03-20 20:46:15 +09:00
Marc-Andre Lafortune 0ef2923c2b Avoid rehashing in Hash#replace/dup/initialize_copy [Bug #16996] 2021-03-18 07:34:40 -04:00
Marc-Andre Lafortune d094c3ef04 Avoid rehashing in Hash#select/reject [Bug #16996] 2021-03-18 07:34:40 -04:00
BurdetteLamar 383685b52b Explicit references to Enumerable 2021-01-20 09:33:41 -08:00
Burdette Lamar 0e015f9389
Adds RDoc summary of Hash methods (#4045)
* Adds RDoc summary of Hash methods
2021-01-10 14:13:24 -06:00
Nobuyoshi Nakada 20a8425aa0
Make any hash values fixable [Bug #17488]
As hnum is an unsigned st_index_t, the result of RSHIFT may not be
in the fixable range.

Co-authored-by: NeoCat <neocat@neocat.jp>
2020-12-31 12:11:45 +09:00
Nobuyoshi Nakada 2eea9156eb
Adjusted indents [ci skip] 2020-12-28 19:43:55 +09:00
Marc-André Lafortune db2ebbd71b
Optimize calls to `Kernel#hash` (#3987)
This avoids recursive checks when the `hash` method of an object
isn't specialized.
2020-12-25 02:08:12 +09:00
Marc-Andre Lafortune 0d3dc2ec80 Make `Hash#except` always return a Hash
[Feature #15822]
2020-12-19 03:59:51 -05:00
Marc-Andre Lafortune 8558d5e480 Document Hash#transform_keys with hash. Amend NEWS [DOC] [ci skip] 2020-12-15 17:09:01 -05:00
Lars Kanis ca76337a00
Windows: Read ENV names and values as UTF-8 encoded Strings (#3818)
* Windows: Read ENV names and values as UTF-8 encoded Strings

Implements issue #12650: fix https://bugs.ruby-lang.org/issues/12650

This also removes the special encoding for ENV['PATH'] and some
complexity in the code that is unnecessary now.

* Windows: Improve readablity of getenv() encoding

getenv() did use the expected codepage as an implicit parameter of the macro.
This is mis-leading since include/ruby/win32.h has a different definition.
Using the "cp" variable explicit (like the other function calls) makes it
more readable and consistent.

* Windows: Change external C-API macros getenv() and execv() to use UTF-8

They used to process and return strings with locale encoding,
but since all ruby-internal spawn and environment functions use UTF-8,
it makes sense to change the C-API equally.
2020-12-08 02:00:39 +09:00
卜部昌平 547c71dec4
Hash#index: delete
Has been deprecated since 0c97c8e335.
2020-12-07 18:35:58 +09:00
卜部昌平 12a121cc0f
ENV.index: delete
Has been deprecated since 373282f665.
2020-12-02 20:17:11 +09:00
Cristian Greco ce3c9a3437 Fix USE_TRANSIENT_HEAP macro usage in hash.c
Additionally fix some typos in transient heap.
2020-11-19 07:11:36 +09:00
Jeremy Evans c0aeb98aa9 Make ENV.replace handle multiple environ entries with the same key
While it is expected that all environment keys are unique, that is
not enforced. It is possible by manipulating environ directly you
can call a process with an environment with duplicate keys.  If
ENV.replace was passed a hash with a key where environ had a
duplicate for that key, ENV.replace would end up deleting the key
from environ.

The fix in this case is to not assume that the environment key
list has unique keys, and continue processing the entire key
list in keylist_delete.

Fixes [Bug #17254]
2020-10-29 08:08:42 -07:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Cristian Greco 6527411f05 [ci skip] Minor documentation fix.
Add missing period.
2020-10-12 15:16:24 +09:00
Kazuhiro NISHIYAMA cece71b467
Add call-seq of [Feature #16274] 2020-09-29 22:49:44 +09:00
bogdanvlviv cdb5258bec Fix `ENV.except`'s docs 2020-09-26 12:02:00 -04:00
Jeremy Evans df14c758fc Make hash returned by Hash#transform_values not have a default
This sets an explicit default of nil.  There is probably a better
approach of removing the default.

Fixes [Bug #17181]
2020-09-21 19:35:08 -07:00
Burdette Lamar 8095114f17
Comply with guide for method doc: hash.c (#3466)
Instance methods considered (most unchanged):
- any
- dig
- \<=
- \<
- \>=
- \>
- to_proc
2020-08-27 14:54:36 -05:00
Burdette Lamar 029c7e6045
Comply with guide for method doc: hash.c (#3465)
Instance methods considered (maybe not all changed):

    invert
    merge!
    merge
    assoc
    rassoc
    flatten
    compact
    compact!
    compare_by_identity
    compare_by_identity?
2020-08-27 13:28:34 -05:00
Burdette Lamar f332fe236c
Comply with guide for method doc: hash.c (#3464)
Instance methods considered (maybe not all changed):

    to_a
    inspect
    to_hash
    to_h
    keys
    values
    include?
    has_value?
    ==
    eql?
    hash
2020-08-27 11:52:29 -05:00
Burdette Lamar b8bfb1d5f5
Comply with guide for method doc: hash.c (#3459)
Instance methods considered (some maybe not changed):

    clear
    []=
    replace
    length
    empty?
    each_value
    each_key
    each_pair
    transform_keys
    transform_keys!
    transform_values
    transform_values!
2020-08-27 08:31:32 -05:00
Burdette Lamar a84a2e872f
Comply with guide for method doc: hash.c (#3454)
Methods reviewed (a few not modified):

    key
    delete
    shift
    delete_if
    reject!
    reject
    slice
    except
    values_at
    fetch_values
    select
    select!
    keep_if
2020-08-25 16:09:31 -05:00
Burdette Lamar 36cc53daae
Comply with guide for method doc: hash.c (#3451)
Methods:

    ::new
    ::[]
    ::try_convert
    #rehash
    #[]
    #fetch
    #default
    #default=
    #default_proc
    #default_proc=
2020-08-25 10:47:23 -05:00
Burdette Lamar 1d3e87a28c
Remove checks for self returned in array.c and hash.c examples (#3446)
Further compliance with https://github.com/ruby/ruby/blob/master/doc/method_documentation.rdoc#details-and-examples-
2020-08-23 12:10:01 -05:00
Burdette Lamar 0fea0427ae
Remove nil-return examples from hash.c (#3438)
* Remove nil-return examples from hash.c
2020-08-21 11:42:02 -05:00
Burdette Lamar 1d1e36fab6
Partial compliance with doc/method_documentation.rdoc in hash.c (#3432)
Removes references to *-convertible thingies.
2020-08-20 07:34:24 -05:00
Marc-Andre Lafortune eae7aef020 [DOC] Improve Hash's doc for missing keys 2020-08-19 19:32:15 -04:00
Marc-Andre Lafortune a586ccf21f [DOC] Improve and simplify key egality documentation for Hash 2020-08-19 19:32:15 -04:00
卜部昌平 99093e1600 RHASH_TBL: is now ext-only
It seems almost no internal codes use RHASH_TBL any longer.  Why not
just eliminate it entirely, so that the macro can be purely ext-only.
2020-08-19 15:10:53 +09:00
Burdette Lamar c84ccf1a07
Fix links to Dig Methods document (#3421)
* Fix links to Dig Methods document

* Fix links to Dig Methods document
2020-08-14 18:55:04 -05:00
Burdette Lamar 22fd617aa5
Adding doc/dig_methods.rdoc and links to it (#3416)
Adds a full discussion of #dig, along with links from Array, Hash, Struct, and OpenStruct.

CSV::Table and CSV::Row are over in ruby/csv. I'll get to them soon.

The art to the thing is to figure out how much (or how little) to say at each #dig.
2020-08-13 13:16:27 -05:00
Benoit Daloze 241244739f Fix arity of Hash#to_proc [Bug #12671] 2020-07-29 18:09:53 +02:00
卜部昌平 1e8461424c rb_hash_transient_heap_evacuate: 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
卜部昌平 5f60538245 any_hash: 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
Timo Schilling 82ca8c7303
Add Hash#except ENV#except [Feature #15822] 2020-06-18 22:47:32 +09:00
Nobuyoshi Nakada 04fddf3573 ENV.delete should return the result of block on non-existing key
Fixes [Bug #16173]

Co-Authored-By: Burdette Lamar <burdettelamar@yahoo.com>
Co-Authored-By: Jeremy Evans <code@jeremyevans.net>
2020-06-10 12:49:27 -07: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 7c2f742c40
Enhanced Rdoc for Hash (#3187)
Methods:

    #<=
    #<
    #>=
    #>
    #to_proc

Also, a small amount of housekeeping: Adding backslash to some class name to prevent linking.
2020-06-07 13:46:43 -05:00
Burdette Lamar e2d76478db
Enhanced Rdoc for Hash (#3178)
* Enhanced Rdoc for Hash

* Fix typo in Hash Rdoc

* Enhanced Rdoc for Hash
2020-06-03 18:53:56 -05:00
Burdette Lamar afefcade98
[ci skip] Enhanced Rdoc for Hash (#3162)
* Enhanced Rdoc for Hash

* Enhanced Rdoc for Hash
2020-06-02 10:53:25 -05:00
S-H-GAMELINKS 6a0405def2 fix typo in Hash#delete docs 2020-06-01 08:11:05 +09:00
Burdette Lamar c1f6552b58
[ci skip] Enhanced Rdoc for Hash (#3155)
* Enhanced Rdoc for Hash

* Respond to review
2020-05-29 13:53:11 -05:00
Burdette Lamar 28ce75821d
Enhanced Rdoc for Hash (#3151) 2020-05-28 06:21:48 -05:00
Burdette Lamar 139839b805
[ci skip] Enhanced Rdoc for Hash (#3143)
* Enhanced Rdoc for Hash

* Respond to review

* Nudge CI testing.
Respond to review
2020-05-27 09:31:22 -05:00
Burdette Lamar 8b8b7c7876
Enhanced Rdoc for Hash (#3139) 2020-05-23 20:35:05 -05:00
BurdetteLamar da484c3187 Enhanced Rdoc for Hash 2020-05-23 12:36:42 +12:00
Burdette Lamar ac395754c7
Enhanced rdoc for Hash (#3129) 2020-05-22 15:05:19 +12:00
S-H-GAMELINKS d707c92a35 add static modifier for rb_hash_keep_if func 2020-05-22 11:51:32 +09:00
S-H-GAMELINKS e5354de9f4 add static modifier for rb_hash_select_bang func 2020-05-22 11:51:32 +09:00
S-H-GAMELINKS 7c4e085938 add static modifier for rb_hash_select func 2020-05-22 11:51:32 +09:00
Burdette Lamar 140d4e4a5f
[ci skip] Enhanced rdoc for Hash (#3121) 2020-05-21 10:57:38 +12:00
S-H-GAMELINKS ff58cbce94 add static modifer for rb_hash_fetch_values func 2020-05-20 23:22:46 +09:00
Burdette Lamar d469807980
[CI skip] Enhance rdoc intro for Hash (#3056)
* Per @nobu review

* [CI skip] Enhance rdoc intro for Hash

* Tweak call-seq for Hash.new

* Tweak call-seq for Hash.new

* Minor corrections

* Respond to review

* Respond to review

* Respond to review

* Respond to review

* Fix chain exampmle

* Response to review
2020-05-15 14:11:42 -07:00
Jeremy Evans de29a022ac Document that #hash is not called for certain core classes [ci skip]
Fixes [Bug #16850]
2020-05-12 18:01:16 -07:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada 5d430c1b34
Added more NORETURN declarations 2020-05-11 00:40:14 +09:00
Burdette Lamar f563f3c5ef
RDoc enhancements for Hash[]. 2020-04-23 20:46:20 +12:00
Nobuyoshi Nakada 0a986b81e1
Env values removed by ENV.clear are not used 2020-04-18 23:19:58 +09:00
Nobuyoshi Nakada 97e8c72e56
Bypass env key encoding conversion if unnecessary 2020-04-18 23:19:58 +09:00
Nobuyoshi Nakada ec4e57cae0
Hoisted out reset_by_modified_env 2020-04-18 23:19:58 +09:00
Nobuyoshi Nakada 08529a6115 Compare environment variable names in those manor [Bug #16798] 2020-04-18 23:09:01 +09:00
Burdette Lamar c28e230ab5
Improve Hash documentation. 2020-04-14 01:57:10 +12:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Burdette Lamar 39c965f230
[ci skip] Doc-only enhancements for Hash
About the defalut values.
2020-03-27 12:33:39 +09:00
Jeremy Evans d2c41b1bff Reduce allocations for keyword argument hashes
Previously, passing a keyword splat to a method always allocated
a hash on the caller side, and accepting arbitrary keywords in
a method allocated a separate hash on the callee side.  Passing
explicit keywords to a method that accepted a keyword splat
did not allocate a hash on the caller side, but resulted in two
hashes allocated on the callee side.

This commit makes passing a single keyword splat to a method not
allocate a hash on the caller side.  Passing multiple keyword
splats or a mix of explicit keywords and a keyword splat still
generates a hash on the caller side.  On the callee side,
if arbitrary keywords are not accepted, it does not allocate a
hash.  If arbitrary keywords are accepted, it will allocate a
hash, but this commit uses a callinfo flag to indicate whether
the caller already allocated a hash, and if so, the callee can
use the passed hash without duplicating it.  So this commit
should make it so that a maximum of a single hash is allocated
during method calls.

To set the callinfo flag appropriately, method call argument
compilation checks if only a single keyword splat is given.
If only one keyword splat is given, the VM_CALL_KW_SPLAT_MUT
callinfo flag is not set, since in that case the keyword
splat is passed directly and not mutable.  If more than one
splat is used, a new hash needs to be generated on the caller
side, and in that case the callinfo flag is set, indicating
the keyword splat is mutable by the callee.

In compile_hash, used for both hash and keyword argument
compilation, if compiling keyword arguments and only a
single keyword splat is used, pass the argument directly.

On the caller side, in vm_args.c, the callinfo flag needs to
be recognized and handled.  Because the keyword splat
argument may not be a hash, it needs to be converted to a
hash first if not.  Then, unless the callinfo flag is set,
the hash needs to be duplicated.  The temporary copy of the
callinfo flag, kw_flag, is updated if a hash was duplicated,
to prevent the need to duplicate it again.  If we are
converting to a hash or duplicating a hash, we need to update
the argument array, which can including duplicating the
positional splat array if one was passed.  CALLER_SETUP_ARG
and a couple other places needs to be modified to handle
similar issues for other types of calls.

This includes fairly comprehensive tests for different ways
keywords are handled internally, checking that you get equal
results but that keyword splats on the caller side result in
distinct objects for keyword rest parameters.

Included are benchmarks for keyword argument calls.
Brief results when compiled without optimization:

  def kw(a: 1) a end
  def kws(**kw) kw end
  h = {a: 1}

  kw(a: 1)       # about same
  kw(**h)        # 2.37x faster
  kws(a: 1)      # 1.30x faster
  kws(**h)       # 2.19x faster
  kw(a: 1, **h)  # 1.03x slower
  kw(**h, **h)   # about same
  kws(a: 1, **h) # 1.16x faster
  kws(**h, **h)  # 1.14x faster
2020-03-17 12:09:43 -07:00
Yusuke Endoh 47141797be hash.c: Do not use the fast path (rb_yield_values) for lambda blocks
As a semantics, Hash#each yields a 2-element array (pairs of keys and
values).  So, `{ a: 1 }.each(&->(k, v) { })` should raise an exception
due to lambda's arity check.
However, the optimization that avoids Array allocation by using
rb_yield_values for blocks whose arity is more than 1 (introduced at
b9d2960337 and some commits), seemed to
overlook the lambda case, and wrongly allowed the code above to work.

This change experimentally attempts to make it strict; now the code
above raises an ArgumentError.  This is an incompatible change; if the
compatibility issue is bigger than our expectation, it may be reverted
(until Ruby 3.0 release).

[Bug #12706]
2020-03-16 23:17:12 +09:00
Alan Wu 713dc619f5 Add missing write barrier for Hash#transform_values{,!}
21994b7fd6 removed the write barrier that
was present in rb_hash_aset(). Re-insert it to not crash during GC.

[Bug #16689]
2020-03-15 18:11:52 -04:00
Koichi Sasada dff69bb462 Cast properly for shift operand
`(int) << RHASH_LEV_SHIFT` can be negative integer.
2020-03-09 02:53:46 +09:00
Koichi Sasada c3584dfacc check ar_table first.
RHASH_AR_TABLE_SIZE() has assertion that it is a ar_talbe.
The last commit breaks this assumption so check ar_table first.
2020-03-07 03:55:54 +09:00
Koichi Sasada 4c019f5a62 check ar_table after `#hash` call
ar_table can be converted to st_table just after `ar_do_hash()`
function which calls `#hash` method. We need to check
the representation to detect this mutation.
[Bug #16676]
2020-03-07 03:34:17 +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
Marcus Stollsteimer 77dcc2c822 hash.c: [DOC] fix examples for ENV.merge! 2020-02-22 16:32:37 +01:00
Burdette Lamar af12e38675
More ENV rdoc [ci skip] 2020-02-22 10:25:54 +09:00
Nobuyoshi Nakada 036a68ae2c
[DOC] Fixed `ENV.rassoc` result order [ci skip] 2020-02-20 08:43:26 +09:00
Marcus Stollsteimer eed7235e33 hash.c: [DOC] fix typos 2020-02-19 20:59:21 +01:00
Nobuyoshi Nakada 125bcdb5cb
[DOC] use local variable like names [ci skip]
Use local variable like name as return value which is an instance
of that class but not constant itself.
2020-02-15 17:32:58 +09:00
Kazuhiro NISHIYAMA 36b7e95744
Fix typos and add a space [ci skip] 2020-02-14 14:26:19 +09:00
Burdette Lamar b9129dac21
Enhanced doc for ENV
* More on ENV examples
2020-02-14 14:18:48 +09:00
Burdette Lamar b7e0831e8f
Enhance rdoc for ENV 2020-02-09 15:59:55 +09:00
Tanaka Akira 338c5b8c1d Extract a function, ruby_reset_timezone().
Initial implementation of ruby_reset_timezone()
assigns ruby_tz_uptodate_p to false.
2020-01-28 23:40:25 +09:00
Nobuyoshi Nakada aefb13eb63
Added rb_warn_deprecated_to_remove
Warn the deprecation and future removal, with obeying the warning
flag.
2020-01-23 21:42:15 +09:00
Jeremy Evans e18b817b1f Make taint warnings non-verbose instead of verbose 2020-01-22 11:19:13 -08:00
Yusuke Endoh 7cfe93c028 hash.c: Add a feature to manipulate ruby2_keywords flag
It was found that a feature to check and add ruby2_keywords flag to an
existing Hash is needed when arguments are serialized and deserialized.
It is possible to do the same without explicit APIs, but it would be
good to provide them as a core feature.

https://github.com/rails/rails/pull/38105#discussion_r361863767

Hash.ruby2_keywords_hash?(hash) checks if hash is flagged or not.
Hash.ruby2_keywords_hash(hash) returns a duplicated hash that has a
ruby2_keywords flag,

[Bug #16486]
2020-01-17 17:20:38 +09:00
Koichi Sasada 350dafd56a reload AR table body for transient heap.
ar_talbe (Hash representation for <=8 size) can use transient heap
and the memory area can move. So we need to restore `pair' ptr after
`func` call (which can run any programs) because of moving.
2020-01-13 03:36:47 +09:00
Nobuyoshi Nakada 7693897a11
Reduced duplicate code 2020-01-10 21:48:20 +09:00
Nobuyoshi Nakada 1b4d406e3a
Hash#transform_values should return a plain new Hash
[Bug #16498]
2020-01-10 21:44:38 +09:00
Nobuyoshi Nakada 5b06dd3a42
Hoisted out call_default_proc 2020-01-08 18:14:04 +09:00
Nobuyoshi Nakada b8fa18079d
Adjusted indents [ci skip] 2020-01-08 18:13:56 +09:00
Lourens Naudé 592d7ceeeb Speeds up fallback to Hash#default_proc in rb_hash_aref by removing a method call 2020-01-08 18:09:52 +09:00
Koichi Sasada 9f460e017b move internal/debug.h definitions to internal.h
Debug utilities should be accessible from any internal code.
2020-01-03 04:46:51 +09:00
Yusuke Endoh 7bf44e9222 `#include "internal/debug"` seems to be needed in assert mode
http://ci.rvm.jp/results/trunk-theap-asserts@silicon-docker/2525210
2019-12-26 21:20:50 +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
卜部昌平 e72b8592d9 internal/hash.h rework
Reduce macros to make them inline functions, as well as mark
MJIT_FUNC_EXPORTED functions explicitly as such.

Definition of ar_hint_t is simplified.  This has been the only possible
definition so far.
2019-12-26 20:45:12 +09:00
Nobuyoshi Nakada b25e27277d
Transform hash keys by a hash [Feature #16274] 2019-12-26 15:50:34 +09:00
BurdetteLamar 890c834ec6
Enhancements for ENV doc 2019-12-22 23:12:15 +09:00
Nobuyoshi Nakada c6c67254fb
Added rb_warn_deprecated 2019-12-19 09:52:17 +09:00
BurdetteLamar d6fd39030d
Enhancements for ENV doc 2019-12-16 23:01:01 +09:00
KOSAKI Motohiro 4d7a6d04b2 Avoid unnecessary tzset() call
Akatsuki reported ENV['TZ'] = 'UTC' improved 7x-8x faster on following code.
t = Time.now; 100000.times { Time.new(2019) }; Time.now - t
https://hackerslab.aktsk.jp/2019/12/01/141551

commit 4bc1669127(reduce tzset) dramatically improved this situation. But still,
TZ=UTC is faster than default.

This patch removs unnecessary tzset() call completely.

Performance check
  ----------------------
test program: t = Time.now; 100000.times { Time.new(2019) }; Time.now - t
before:         0.387sec
before(w/ TZ):  0.197sec
after:          0.162sec
after(w/ TZ):   0.165sec

OK. Now, Time creation 2x faster *and* TZ=UTC doesn't improve anything.
We can forget this hack completely. :)

Side note:
This patch slightly changes Time.new(t) behavior implicitly. Before this patch, it might changes
default timezone implicitly. But after this patch, it doesn't. You need to reset TZ
(I mean ENV['TZ'] = nil) explicitly.
But I don't think this is big impact. Don't try to change /etc/localtime on runtime.

Side note2: following test might be useful for testing "ENV['TZ'] = nil".
  -----------------------------------------
% cat <<'End' | sudo sh -s
rm -f /etc/localtime-; cp -a /etc/localtime /etc/localtime-
rm /etc/localtime; ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
./ruby -e '
p Time.new(2000).zone # JST
File.unlink("/etc/localtime"); File.symlink("/usr/share/zoneinfo/America/Los_Angeles", "/etc/localtime")
p Time.new(2000).zone # JST (ruby does not follow /etc/localtime modification automatically)
ENV["TZ"] = nil
p Time.new(2000).zone # PST (ruby detect /etc/localtime modification)
'
rm /etc/localtime; cp -a /etc/localtime- /etc/localtime; rm /etc/localtime-
End
2019-12-01 16:34:26 +00:00
Nobuyoshi Nakada 5e0479f26a ENV.update should not call block on existing keys
[Bug #16192]
2019-11-30 18:18:20 +01:00
Kazuhiro NISHIYAMA 09e76e9828
Improve consistency of bool/true/false 2019-11-25 15:09:09 +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
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.

This modifies some internal functions that took a safe level argument
to no longer take the argument.

rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.

One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd.  We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
2019-11-18 01:00:25 +02:00
卜部昌平 c9ffe751d1 delete unused functions
Looking at the list of symbols inside of libruby-static.a, I found
hundreds of functions that are defined, but used from nowhere.

There can be reasons for each of them (e.g. some functions are
specific to some platform, some are useful when debugging, etc).
However it seems the functions deleted here exist for no reason.

This changeset reduces the size of ruby binary from 26,671,456
bytes to 26,592,864 bytes on my machine.
2019-11-14 20:35:48 +09:00
John Hawthorn b99833baec
Use a monotonically increasing number for object_id
This changes object_id from being based on the objects location in
memory (or a nearby memory location in the case of a conflict) to be
based on an always increasing number.

This number is a Ruby Integer which allows it to overflow the size of a
pointer without issue (very unlikely to happen in real programs
especially on 64-bit, but a nice guarantee).

This changes obj_to_id_tbl and id_to_obj_tbl to both be maps of Ruby
objects to Ruby objects (previously they were Ruby object to C integer)
which simplifies updating them after compaction as we can run them
through gc_update_table_refs.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2019-11-07 09:31:07 -08:00
Aaron Patterson e58814d150
Revert "Use a monotonically increasing number for object_id"
This reverts commit bd2b314a05.
2019-11-06 15:12:28 -08:00
John Hawthorn bd2b314a05 Use a monotonically increasing number for object_id
This changes object_id from being based on the objects location in
memory (or a nearby memory location in the case of a conflict) to be
based on an always increasing number.

This number is a Ruby Integer which allows it to overflow the size of a
pointer without issue (very unlikely to happen in real programs
especially on 64-bit, but a nice guarantee).

This changes obj_to_id_tbl and id_to_obj_tbl to both be maps of Ruby
objects to Ruby objects (previously they were Ruby object to C integer)
which simplifies updating them after compaction as we can run them
through gc_update_table_refs.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2019-11-06 14:59:53 -08:00
Nobuyoshi Nakada 7c3bc0aa13
Put an empty line [ci skip] 2019-11-05 08:07:59 +09:00
Burdette Lamar 74bb8fb348 More rdoc for ENV 2019-11-05 08:03:01 +09:00
Burdette Lamar 772b0613c5 Correct documented return values for certain ENV methods (#2620) 2019-11-02 15:32:49 +09:00
Yusuke Endoh f26f0f4109 hash.c: Do not use Unicode double-quotes
It made rdoc fail.

https://rubyci.org/logs/rubyci.s3.amazonaws.com/ubuntu1804/ruby-master/log/20191023T183005Z.fail.html.gz
```
RDoc is not a full Ruby parser and will fail when fed invalid ruby programs.

The internal error was:

	(ArgumentError) invalid byte sequence in US-ASCII

uh-oh! RDoc had a problem:
invalid byte sequence in US-ASCII
```
2019-10-24 08:04:45 +09:00
BurdetteLamar df91896f32 More rdoc for ENV#[] and ENV#fetch 2019-10-23 11:12:22 -07:00
Nobuyoshi Nakada 5d63a9da40
[Bug #16121] adjusted indent [ci skip] 2019-10-21 17:45:27 +09:00
Dylan Thacker-Smith b970259044 Stop making a redundant hash copy in Hash#dup (#2489)
* Stop making a redundant hash copy in Hash#dup

It was making a copy of the hash without rehashing, then created an
extra copy of the hash to do the rehashing.  Since rehashing creates
a new copy already, this change just uses that rehashing to make
the copy.

[Bug #16121]

* Remove redundant Check_Type after to_hash

* Fix freeing and clearing destination hash in Hash#initialize_copy

The code was assuming the state of the destination hash based on the
source hash for clearing any existing table on it. If these don't match,
then that can cause the old table to be leaked. This can be seen by
compiling hash.c with `#define HASH_DEBUG 1` and running the following
script, which will crash from a debug assertion.

```ruby
h = 9.times.map { |i| [i, i] }.to_h
h.send(:initialize_copy, {})
```

* Remove dead code paths in rb_hash_initialize_copy

Given that `RHASH_ST_TABLE_P(h)` is defined as `(!RHASH_AR_TABLE_P(h))`
it shouldn't be possible for a hash to be neither of these, so there
is no need for the removed `else if` blocks.

* Share implementation between Hash#replace and Hash#initialize_copy

This also fixes key rehashing for small hashes backed by an array
table for Hash#replace.  This used to be done consistently in ruby
2.5.x, but stopped being done for small arrays in ruby 2.6.x.

This also bring optimization improvements that were done for
Hash#initialize_copy to Hash#replace.

* Add the Hash#dup benchmark
2019-10-21 17:29:21 +09:00
Nobuyoshi Nakada ce7942361d
Use identhash as WeakMap
As ObjectSpace::WeakMap allows FLONUM as a key, needs the special
deal for its hash.  [Feature #16035]
2019-10-18 14:53:51 +09:00
Burdette Lamar 6a1809e2e1 Enhance doc for ENV.delete 2019-10-13 09:48:20 +09:00
Jeremy Evans 660c7e050f Fix more keyword separation issues
This fixes instance_exec and similar methods. It also fixes
Enumerator::Yielder#yield, rb_yield_block, and a couple of cases
with Proc#{<<,>>}.

This support requires the addition of rb_yield_values_kw, similar to
rb_yield_values2, for passing the keyword flag.

Unlike earlier attempts at this, this does not modify the rb_block_call_func
type or add a separate function type.  The functions of type
rb_block_call_func are called by Ruby with a separate VM frame, and we can
get the keyword flag information from the VM frame flags, so it doesn't need
to be passed as a function argument.

These changes require the following VM functions accept a keyword flag:

* vm_yield_with_cref
* vm_yield
* vm_yield_with_block
2019-09-26 19:24:58 -07:00
Jeremy Evans 27144de2bd Fix documentation for ENV.each to return ENV
Also have spec check that it returns ENV.

Mostly from burdettelamar@yahoo.com (Burdette Lamar).

Fixes [Bug #16164]
2019-09-20 12:18:07 -07:00
John Hawthorn 21994b7fd6 Avoid rehashing keys in transform_values
Previously, calling transform_values would call rb_hash_aset for each
key, needing to rehash it and look up its location.

Instead, we can use rb_hash_stlike_foreach_with_replace to replace the
values as we iterate without rehashing the keys.
2019-09-11 14:23:11 -07:00
Jeremy Evans 334b41a46b Allow ** syntax to be used for calling methods that do not accept keywords
Treat the ** syntax as passing a copy of the hash as the last
positional argument.  If the hash being double splatted is empty, do
not add a positional argument.

Remove rb_no_keyword_hash, no longer needed.
2019-08-30 12:39:31 -07:00
Yusuke Endoh 16c6984bb9 Separate keyword arguments from positional arguments
And, allow non-symbol keys as a keyword arugment
2019-08-30 12:39:31 -07:00
卜部昌平 3df37259d8 drop-in type check for rb_define_singleton_method
We can check the function pointer passed to
rb_define_singleton_method like how we do so in rb_define_method.
Doing so revealed many arity mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平 50f5a0a8d6 rb_hash_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit adds function prototypes
for rb_hash_foreach / st_foreach_safe.  Also fixes some prototype
mismatches.
2019-08-27 15:52:26 +09:00
Jeremy Evans e1c991f8d7 Move Object#hash rdoc to hash.c [ci skip]
This gets RDoc to pick up the documentation correctly.

Problem pointed out by zverok (Victor Shepelev).
2019-08-24 09:09:53 -07:00
Yusuke Endoh 3229e0583f hash.c: gc.h is needed when HASH_DEBUG mode 2019-08-07 22:54:38 +09:00
Yusuke Endoh 0cf6bfca78 hash.c: gc.h is no longer needed 2019-08-07 22:43:02 +09:00
Daniel Radetsky 82527d9b50
fix spelling
Closes: https://github.com/ruby/ruby/pull/2323
2019-08-07 22:25:50 +09:00
Koichi Sasada 3a6f51ee35 introduce ar_hint_t.
Hash hint for ar_array is 1 byte (unsigned char). This patch introduce
ar_hint_t which represents hint type.
2019-08-01 16:06:43 +09:00
Koichi Sasada 7463867106 use internal_id.
"hash_iter_lev" can be exported by Marshal.dump and it will
introduce inconsistency. To avoid this issue, use internal_id
instead of normal ID. This issue is pointed out by Chikanaga-san.
2019-08-01 11:22:43 +09:00
Koichi Sasada 117241b3c7 make inline functions from macros. 2019-08-01 05:59:04 +09:00
Koichi Sasada bd1052d55d use hash_ar_table_set() directly 2019-07-31 21:50:58 +01:00
Koichi Sasada deddc80476 HASH_ASSERT() respects HASH_DEBUG 2019-07-31 21:48:22 +01:00
Koichi Sasada 312879693f move macro to internal.h for documentation.
13e84d5c0a changes enum to macro, but the flags usage information
are lost in internal.h. It should be same place with other flags
information.
2019-07-31 11:32:14 +09:00
Nobuyoshi Nakada 13e84d5c0a
Moved RHASH_LEV_MASK and turned into a macro
Get rid of "ISO C restricts enumerator values to range of 'int'"
error.
2019-07-31 11:08:05 +09:00
git e315f3a134 * expand tabs. 2019-07-31 10:22:47 +09:00
Koichi Sasada 72825c35b0 Use 1 byte hint for ar_table [Feature #15602]
On ar_table, Do not keep a full-length hash value (FLHV, 8 bytes)
but keep a 1 byte hint from a FLHV (lowest byte of FLHV).
An ar_table only contains at least 8 entries, so hints consumes
8 bytes at most. We can store hints in RHash::ar_hint.

On 32bit CPU, we use 4 entries ar_table.

The advantages:
* We don't need to keep FLHV so ar_table only consumes
  16 bytes (VALUEs of key and value) * 8 entries = 128 bytes.
* We don't need to scan ar_table, but only need to check hints
  in many cases. Especially we don't need to access ar_table
  if there is no match entries (in many cases).
  It will increase memory cache locality.

The disadvantages:
* This technique can increase `#eql?` time because hints can
  conflicts (in theory, it conflicts once in 256 times).
  It can introduce incompatibility if there is a object x where
  x.eql? returns true even if hash values are different.
  I believe we don't need to care such irregular case.
* We need to re-calculate FLHV if we need to switch from ar_table
  to st_table (e.g. exceeds 8 entries).
  It also can introduce incompatibility, on mutating key objects.
  I believe we don't need to care such irregular case too.

Add new debug counters to measure the performance:
* artable_hint_hit - hint is matched and eql?#=>true
* artable_hint_miss - hint is not matched but eql?#=>false
* artable_hint_notfound - lookup counts
2019-07-31 09:52:03 +09:00
Koichi Sasada ebd398ac5a remove RHash::iter_lev.
iter_lev is used to detect the hash is iterating or not.
Usually, iter_lev should be very small number (1 or 2) so
`int` is overkill.

This patch introduce iter_lev in flags (7 bits, FL13 to FL19)
and if iter_lev exceeds this range, save it in hidden attribute.
We can get 1 word in RHash.

We can't modify frozen objects. Therefore I added new internal API
`rb_ivar_set_internal()` which allows us to set an attribute
even if the target object is frozen
if the name is hidden ivar (the name without `@` prefix).
2019-07-31 09:44:23 +09:00
Nobuyoshi Nakada a036a8a038
Adjust styles and indents 2019-07-19 06:35:15 +09:00
Koichi Sasada c23e597674 respect RUBY_DEBUG.
see RUBY_DEBUG for each debug options.
2019-07-15 11:30:34 +09:00
Nobuyoshi Nakada bdddaa9f56
Use rb_ident_hash_new instead of rb_hash_new_compare_by_id
The latter is same as the former, removed the duplicate function.
2019-07-03 02:09:01 +09:00
Jeremy Evans f53d7e4bfd Raise TypeError if calling ENV.freeze
Previously, you could call ENV.freeze, but it would not have
the desired effect, as you could still modify ENV.

Fixes [Bug #15920]
2019-07-01 12:39:06 -07:00
Kenichi Kamiya d01fd82187 Alias ENV.merge! as ENV.update
[Feature #15947]

Closes: https://github.com/ruby/ruby/pull/2246
2019-06-21 18:25:01 +02:00
Yusuke Endoh d3f1c615c5 hash.c (rb_hash_s_create): Reject `Hash[[nil]]`
The behavior of `Hash[[nil]] #=> {}` was a bug until 1.9.3, but had been
remained with a warning because some programs depended upon it.
Now, six years passed.  We can remove the compatibility behavior.
[Bug #7300]
2019-05-23 00:19:56 +09:00
Aaron Patterson 75061f46ae
Fix complex hash keys to work with compaction
For example when an array containing objects is a hash key, the contents
of the array may move which can cause the hash value for the array to
change.   This commit makes the default `hash` value based off the
object id, so the hash value will remain stable.

Fixes test/shell/test_command_processor.rb
2019-04-23 14:21:15 -07:00
k0kubun 683834eb72 Drop MJIT_FUNC_EXPORTED from rb_hash_bulk_insert
it's official API after r67677

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-21 08:34:37 +00:00
tenderlove 91793b8967 Add `GC.compact` again.
🙏

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20 01:19:47 +00:00
tenderlove 744e5df715 Reverting compaction for now
For some reason symbols (or classes) are being overridden in trunk

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 09:41:41 +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
tenderlove 3c55b643ae Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 03:17:25 +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
tenderlove 3ef4db15e9 Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-09 20:32:04 +00:00
nobu 56557ec28a [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22 11:04:59 +00:00
svn 8092d571be * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-27 03:26:09 +00:00
nobu 5e2a8cb7b9 Remove stale arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67134 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-27 03:26:05 +00:00
nobu e1e3d642bf hash.c: hoisted out st_index_hash
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 05:08:36 +00:00
nobu a94b78e418 hash.c: hoisted out dbl_to_index
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66945 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 04:54:01 +00:00
svn ef17936bc5 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 03:36:09 +00:00
nobu d07d192881 hash.c: remove repeated rb_hash_start
* hash.c (rb_dbl_long_hash): remove repeated rb_hash_start as
  rb_objid_hash includes rb_hash_start,

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 03:36:06 +00:00
ko1 367fdd1aee reset bound if the size is 0.
* hash.c (RHASH_AR_TABLE_SIZE_DEC): generally, we need to check all
  entries to calculate exact "bound" in ar_table, but if size == 0,
  we can clear bound because there are no active entries.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-17 07:52:47 +00:00
ko1 e3dbe84e12 add setter of iter_lev.
* hash.c: add special setter function (inc and dec).

* internal.h: constify RHash::iter_leve.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09 19:11:32 +00:00
ko1 fc7f990666 fix last commit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 22:41:59 +00:00
ko1 93583166c8 refactoring.
* hash.c (EQUAL, PTR_EQUAL): make corresponding inline functions
  ar_equal() and ar_ptr_equal().

* hash.c (SET_*): removed. set fields directly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 22:40:32 +00:00
ko1 70caae18f2 add ar_ prefix for ar_table functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 22:23:54 +00:00
ko1 0c0d181e0f fix trivial indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 00:31:54 +00:00
ko1 2380111008 call functions directly.
* hash.c: ar_table only supports `objhash` so we can call compare/hash
  functions directly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 00:06:09 +00:00
ko1 3a144485fc refactoring usage of ar_lookup().
* hash.c (hash_stlike_lookup): introduce inline a function and use it
  instead of using ar_lookup()/st_lookup() directly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-04 23:48:33 +00:00
ko1 87e628d66b skip to calculate hash value on empty Hash ar_table lookup.
* hash.c (ar_lookup): don't calculate hash_value if ar_table is empty.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-04 07:49:00 +00:00
ko1 ba4672c2cb ar_table_entry::hash should be `st_hash_t`.
* hash.c: the type of `ar_table_entry::hash` is not a `VALUE`,
  but a `st_hash_t`.
  Also `st_hash_t` is not a `st_data_t`, but `st_index_t` (same as st.c).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-04 01:59:49 +00:00
ko1 8ee0a8e91a hide ar_table internals from internal.h.
* internal.h: move ar_table def to hash.c because other files
  don't need to know implementation of ar_table.

* hash.c (rb_hash_ar_table_size): added because gc.c needs to know
  the size_of(ar_table).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-29 16:29:44 +00:00
ko1 2a70f68c05 hide iseq operand object for duphash. [Bug #15440]
* compile.c (compile_array): hide source Hash object.

* hash.c (rb_hash_resurrect): introduced to dup Hash object
  using rb_cHash.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-20 07:17:55 +00:00
ko1 bb0eb3bf1f separte NULL and EMPTY check.
* hash.c: separate NULL and EMPTY check functions.
  `RHASH_TABLE_EMPTY` function checks NULL table or not,
  but it should be named "NULL_P".
  Introduce `RHASH_TABLE_EMPTY_P` function to check size == 0.
  There are cases that hash has table data even if data is not NULL
  (in case removed after inserted elements).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-14 02:27:23 +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 485f3b57bc Initialize bin
* hash.c (linear_update): initialize `bin` just to silence false
  warnings by old gcc 4.8.  [Bug #15299]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-10 02:01:21 +00:00
nobu d60738f6f1 Adjust reserved hash values
The reserved hash values in hash.c must be consistend with st.c.
[ruby-core:90356] [Bug #15389]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-07 12:03:16 +00:00
nobu 1e9eb83928 Should use the proper constant
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-07 11:45:03 +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
ko1 a763e3460f clear dst Hash on Hash#replace. [Bug #15358]
* hash.c (linear_copy): solve two issues on `Hash#replace`.
  (1) fix memory leak
      (1-1) don't allocate memory if destination already
            has a memory area.
      (1-2) free destination memory if src is NULL.
  (2) clear transient heap flag if src is NULL. [Bug #15358]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29 08:03:55 +00:00
shyouhei f98004c0f2 hash.c: cast from double to unsigned is undefined
When a negative double is casted into an unsigned type, that operation
is undefined (cf: ISO/IEC 9899:1990 section 6.2.9.3).  Recent versions
of C kindly footnotes that "The remaindering operation performed when
a value of integer type is converted to unsigned type need not be
performed when a value of real floating type is converted to unsigned
type" (cf: ISO/IEC 9899:1999 section 6.3.1.4 footnote 50).

So it is a wrong idea to just cast a double to st_data_t.

The intention of the code is commented as "mix the actual float value
in".  It seems we should do a reinterpret_cast and rule out
static_cast.

Confirmed this changeset does not affect `make benchmark`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-15 06:17:53 +00:00
shyouhei 3483e6dad4 hash.c: +(-1) is a wrong idea
Before this changeset RHASH_ARRAY_SIZE_DEC() was expaneded to include
an expression like `RHASH_ARRAY_SIZE+(-1)`.  RHASH_ARRAY_SIZE is by
definition unsigned int.  -1 is signed, of course.  Adding a signed
and an unsigned value requires the "usual arithmetic conversions" (cf:
ISO/IEC 9899:1990 section 6.2.1.5).  -1 is converted to 0xFFFF by that.

This patch prevents that conversion.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08 07:41:24 +00:00
stomar 2c62b3fbc7 hash.c: [DOC] add docs for ENV.{filter,filter!}
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04 11:46:49 +00:00
stomar 7633552b1d hash.c: [DOC] fix wrong cross-references
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04 11:45:59 +00:00
stomar 45868d20f4 hash.c: [DOC] add missing `block' in call-seq's
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04 11:45:11 +00:00
stomar 83e459b2f3 hash.c: [DOC] add docs for Hash#{filter,filter!}
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04 11:43:09 +00:00
stomar b3adc0c564 hash.c: [DOC] improve Hash#{select!,keep_if} docs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04 11:41:52 +00:00
nobu 84a27619e5 hash.c: fix types
* hash.c (RHASH_ARRAY_BOUND_RAW): should be unsigned as well as
  RHASH_ARRAY_SIZE_RAW.

* hash.c (find_entry): return unsigned for the consistency with
  RHASH_ARRAY_SIZE and RHASH_ARRAY_BOUND.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-03 07:58:56 +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