Commit Graph
113 Commits
Author SHA1 Message Date
Hiroshi SHIBATAandClaude Opus 5 77f04f52ee Use rb_len_t for lengths in hash.c, st.c and set.c
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-09 14:00:15 +09:00
Nobuyoshi Nakada f61ac22c23 Avoid potentially type-punning casts 2026-10-01 19:05:51 +09:00
Nobuyoshi Nakada badce4d079 Add a more defensive GC guard 2026-10-01 19:05:50 +09:00
Nobuyoshi Nakada 3ea4bc3f79 [Bug #22388] Fix use-after-free in Set#& 2026-10-01 19:04:05 +09:00
Gil DesmaraisandJeremy Evans f069efc3f6 Preserve compare_by_identity in some Set operations
Adjust the specs to handle the backwards compatibility breakage.
While we will backport this to Ruby 4.0, to avoid temporary
breakage, leave Ruby 4.0 behavior unspecified until the fixes
are backported to it.

Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-09-23 20:01:54 -07:00
Nobuyoshi Nakada 74856fbfb6 Use identity sets to track unspecified keyword arguments
Keyword tracking only needs membership, so replace identity hashes
with identity sets to avoid storing unused values.  Add `rb_set_p`
for the type assertion in `vm_check_keyword`.

Add benchmarks for 31, 32 and 128 keyword parameters with sparse and
dense dynamic defaults, using both direct keywords and keyword splats.
The 31-parameter cases provide a bitmask-only control.

Local arm64 macOS measurements show about 16-26% higher throughput
with many omitted dynamic defaults at 32 and 128 parameters.  Smaller
differences remain noisy, including in the bitmask-only controls.

The tracking container is created at call time, leaving IBF and
`ISeq#to_a` unchanged.  Verify IBF-loaded calls with the Integer
refinement and colliding keyword indices from [Bug #22335].
2026-09-23 21:36:41 +09:00
Peter Zhu 41cf062956 Use Set instead of Hash for Array#&
This commit changes Array#& to use a temporary Set instead of Hash for
performance and memory savings. We can see in the following benchmark:

    a = (0...10_000).to_a
    b = (5_000...15_000).to_a

    1_000.times { a & b }

Results:

    Benchmark 1: master
      Time (mean ± σ):     196.4 ms ±   9.1 ms    [User: 182.9 ms, System: 9.5 ms]
      Range (min … max):   186.3 ms … 214.7 ms    13 runs

    Benchmark 2: branch
      Time (mean ± σ):     163.4 ms ±   3.3 ms    [User: 152.7 ms, System: 7.8 ms]
      Range (min … max):   157.7 ms … 169.9 ms    17 runs

    Summary
      branch ran
        1.20 ± 0.06 times faster than master
2026-09-13 11:52:30 +09:00
Peter Zhu 078196c12d Use Set instead of Hash for Array#|
This commit changes Array#| to use a temporary Set instead of Hash for
performance and memory savings. We can see in the following benchmark:

    a = (0...10_000).to_a
    b = (5_000...15_000).to_a

    1_000.times { a | b }

Results:

    Benchmark 1: master
      Time (mean ± σ):     237.5 ms ±   2.0 ms    [User: 223.4 ms, System: 10.9 ms]
      Range (min … max):   234.6 ms … 240.7 ms    12 runs

    Benchmark 2: branch
      Time (mean ± σ):     165.2 ms ±   3.8 ms    [User: 151.2 ms, System: 10.8 ms]
      Range (min … max):   159.8 ms … 174.2 ms    18 runs

    Summary
      branch ran
        1.44 ± 0.04 times faster than master
2026-09-13 11:52:30 +09:00
Peter Zhu 35f46c051f Create internal/set.h for set.c function definitions 2026-09-12 20:07:25 +09:00
Jeremy Evans 85220035ca Add rb_ident_set_new internal function
This is designed to replace rb_ident_hash_new calls when such hashes
are used purely with with true values.

To implement this, add a set_alloc_with_size_and_type static function,
and have set_alloc_with_size and rb_ident_set_new call it.
2026-08-25 07:03:04 -07:00
Jean Boussier fb99639ed9 Get rid of rb_hash_new_with_size
It's redundant with `rb_hash_new_capa` which is public API,
might as well use that one.
2026-08-16 13:50:22 +02:00
Burdette Lamar 7c5e7a5032 [DOC] Remove stale link in Set doc 2026-07-27 14:00:41 -07:00
Jeremy Evans 388ea3c3cf Compact sets after removal of items for more methods
This changes the following methods to compact the set after removal:

* `^`
* `-`
* `difference`
* `subtract`
* `keep_if`
* `select!`
* `filter!`

Fixes [#22210]
2026-07-27 09:13:47 -07:00
Jean Boussier 8645a948c0 Right size temporary dump objects
The Range Marshal compat dumper would allocate
an Object with no size information, hence get a 32B slot
with enough space for 2 ivars, then insert 3 ivars causing
it to spill.

This isn't a big problem, but somewhat shows that the interface
isn't WVA aware.

By introducing `rb_class_allocate_instance_capa` we can directly
allocate an object with enough room.
2026-07-22 23:52:01 +02:00
Hiroshi SHIBATAandClaude Opus 4.8 6f8d0dd256 Fix Set RDoc examples to use Set and proper output comments
Set#include? built its receiver from an Array literal, so the
`hash`/`eql?` semantics the surrounding text describes did not apply.
Set#each wrote `sum => 6`, which is a rightward-assignment pattern
match rather than an output comment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 15:19:19 +09:00
Burdette Lamar b9be3d6b6d [DOC] Minor updates to Set documentation 2026-07-09 22:12:29 -07:00
Jeremy Evans 07f700f3fd [DOC] Fix missed * in Set class documentation 2026-07-08 00:38:58 -07:00
Burdette LamarandJeremy Evans 33d53874c0 [DOC] Update Set class documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-07-08 00:26:18 -07:00
Burdette Lamar a1515f149e [DOC] Remove Set Methods for Iterating documentation section
This section only had one method (#each), so move that
method to the "Other Methods" section.
2026-07-07 00:13:58 -07:00
Burdette LamarandJeremy Evans bcbf54feb4 [DOC] Update Set Methods for Converting documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-07-07 00:11:56 -07:00
Burdette LamarandJeremy Evans b7856ca0f2 [DOC] Update Set Methods for Deleting documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-07-07 00:10:51 -07:00
Burdette Lamar c6550f2109 [DOC] Update Set Methods for Assigning documentation 2026-07-06 17:27:09 -07:00
Burdette Lamar 9bda75a612 [DOC] Update Set Methods for Querying documentation 2026-07-06 17:26:15 -07:00
Burdette LamarandJeremy Evans a8e5c2f9be [DOC] Update Set create methods documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-07-03 01:23:10 -07:00
Burdette Lamar 354806506c [DOC] Update Set operations methods documentation 2026-07-02 17:25:06 -07:00
Burdette LamarandJeremy Evans 677f9f5a29 [DOC] Update Set#size documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-07-02 17:20:53 -07:00
Burdette LamarandJeremy Evans 82979eed5a [DOC] Update Set assign methods documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-07-02 17:16:58 -07:00
Burdette LamarandJeremy Evans b5dc95c649 [DOC] Update Set#to_set documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-07-02 17:13:33 -07:00
Burdette Lamar 961ca26e6f [DOC] Update Set#to_a documentation 2026-07-01 23:57:33 -07:00
Burdette Lamar 22f006cd89 [DOC] Update Set#superset? documentation 2026-07-01 23:56:57 -07:00
Burdette Lamar 722e44f68e [DOC] Update Set#subtract documentation 2026-07-01 23:56:20 -07:00
Burdette Lamar e4a403ebd7 [DOC] Update Set#subset? documentation 2026-07-01 23:55:14 -07:00
Burdette Lamar 426899ea64 [DOC] Update Set#select! documentation 2026-07-01 23:52:49 -07:00
Burdette LamarandJeremy Evans 266f1f246e [DOC] Update Set#compare_by_identity{,?} documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-07-01 23:52:05 -07:00
Burdette LamarandJeremy Evans a86a1a77b3 [DOC] Update Set#reset documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-06-30 17:47:31 -07:00
Burdette LamarandJeremy Evans a39081efea [DOC] Update Set#replace documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-06-30 17:46:10 -07:00
Burdette LamarandJeremy Evans 54eead3b78 [DOC] Update Set#proper_superset? documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-06-30 17:45:21 -07:00
Burdette LamarandJeremy Evans 298791a4bf [DOC] Update Set#proper_subset? documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-06-30 17:44:11 -07:00
Burdette LamarandJeremy Evans 1a8320b3ff [DOC] Update Set#merge documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-06-30 17:43:27 -07:00
Burdette LamarandJeremy Evans c5eb119f31 [DOC] Update Set#hash documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-06-30 17:42:43 -07:00
Burdette Lamar 29e4bf19b1 [DOC] Update Set#reject! documentation 2026-06-30 15:46:31 -07:00
Burdette Lamar 597dcfb04a [DOC] Update Set#keep_if documentation 2026-06-30 15:41:34 -07:00
d88016de4f [DOC] Update Set#divide documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
Co-authored-by: tompng <tomoyapenguin@gmail.com>
2026-06-30 15:38:00 -07:00
Burdette LamarandJeremy Evans a291454c76 [DOC] Update Set#join documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-06-28 23:48:10 -07:00
Burdette LamarandJeremy Evans d945702c28 [DOC] Update Set#include? documentation
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2026-06-28 23:46:53 -07:00
Burdette Lamar f2e09df297 [DOC] Update Set#each documentation 2026-06-28 23:44:48 -07:00
Burdette Lamar cf979af0af [DOC] Update Set#intersect? documentation 2026-06-28 11:02:23 -07:00
Burdette Lamar 40c2f61195 [DOC] Update Set#inspect documentation 2026-06-28 11:00:48 -07:00
Burdette Lamar 73a6e69de1 [DOC] Update Set#flatten! documentation 2026-06-28 10:48:05 -07:00
Burdette Lamar f3009a1e2a [DOC] Update Set#flatten documentation 2026-06-28 10:46:17 -07:00