Commit Graph

17099 Commits

Author SHA1 Message Date
John Bampton b4a1e98f2e Rubocop: fix target Ruby version; add two more cops; fix lint error
https://docs.rubocop.org/rubocop/cops_layout.html#layoutassignmentindentation

https://docs.rubocop.org/rubocop/cops_layout.html#layoutblockendnewline
2025-06-25 18:02:53 +10:00
Yukihiro "Matz" Matsumoto 84a4bd16ac Merge pull request #6563 from jbampton/rubocop-indentation 2025-06-25 16:12:27 +09:00
Yukihiro "Matz" Matsumoto e333c9fbc9 Merge pull request #6562 from jbampton/misc-fix-spelling-word-case 2025-06-25 16:10:38 +09:00
Yukihiro "Matz" Matsumoto dfb065c95a Merge pull request #6564 from jbampton/remove-jumanjihouse-hooks 2025-06-25 16:09:10 +09:00
Yukihiro "Matz" Matsumoto 0edd0aec73 mruby-set: use KSET_FOREACH macro extensively
Implemented by: Rovo Dev
2025-06-25 13:33:39 +09:00
Yukihiro "Matz" Matsumoto fc6d7cc424 mruby-set: new helper function set_ensure_initialized 2025-06-25 13:23:21 +09:00
Yukihiro "Matz" Matsumoto 29bc46703b mruby-set: small refactoring 2025-06-25 13:22:13 +09:00
Yukihiro "Matz" Matsumoto b1dc550892 mruby-set: remove names with kh that stands for khash no longer used 2025-06-25 13:06:21 +09:00
Yukihiro "Matz" Matsumoto 0d1c22150e mruby-set: Simplify code with convenience macros and cleanup
Add convenience macros to reduce code duplication and improve readability:

- kset_is_uninitialized(s) for checking uninitialized sets
- kset_is_empty(s) for checking empty sets
- KSET_FOREACH(s, k) for iterating over set elements

Replace repetitive manual checks and for-loops throughout the codebase
with these macros.

Implemented by: Rovo Dev
2025-06-25 11:17:53 +09:00
John Bampton 62f4de0c01 Remove jumanjihouse pre-commit hooks no longer maintained 2025-06-25 12:11:06 +10:00
John Bampton 4e5db98128 pre-commit add rubocop with one rule spaces for indentation
https://docs.rubocop.org/rubocop/integration_with_other_tools.html#git-pre-commit-hook-integration-with-pre-commit
2025-06-25 12:02:35 +10:00
Yukihiro "Matz" Matsumoto a82911b35f mruby-set: replace khash dependency with embedded kset implementation
Replace the external khash dependency with a custom, memory-optimized
kset implementation that embeds directly into struct RSet. This change
significantly reduces memory consumption and eliminates the need for
khash.h inclusion.

Implemented by: Rovo Dev

Key improvements:
- Embedded kset_t directly in struct RSet (exactly 3 pointers in size)
- Combined memory layout: [keys...][flags...] in single allocation
- Eliminated pointer indirection for better cache performance
- Removed dependency on khash.h and related types (khint_t, khiter_t)
- Maintained full API compatibility with existing mruby-set interface
- Optimized for mrb_value keys with custom hash and equality functions

Technical details:
- kset_t structure: void *data, uint32_t n_buckets, uint32_t size
- Open addressing with linear probing for collision resolution
- 2-bit flags per bucket (empty/deleted) packed efficiently
- Power-of-2 bucket sizing with 75% load factor upper bound
- Integrated GC marking and memory management

Memory savings:
- Eliminates separate khash_t allocation and pointer storage
- Reduces struct RSet from 4 pointers to 3 pointers + embedded data
- More efficient memory layout with better locality of reference

All existing functionality preserved including set operations, iteration,
comparison methods, and Ruby-level API compatibility.
2025-06-25 10:53:42 +09:00
John Bampton 383cd6a936 misc: fix spelling word case 2025-06-25 10:46:23 +10:00
Yukihiro "Matz" Matsumoto 88a7b782c6 Merge pull request #6560 from mruby/set-gc-marking-v2 2025-06-24 14:10:22 +09:00
Yukihiro "Matz" Matsumoto a6a0346e1c mruby-os-memsize: support Set class 2025-06-24 13:56:07 +09:00
Yukihiro "Matz" Matsumoto 132561418b mruby-set: update Set class to use struct RSet not struct RData 2025-06-24 13:45:14 +09:00
google-labs-jules[bot] dfd7251223 Refactor: Improve Set GC marking and freeing
This commit addresses feedback on the initial Set GC marking implementation.

Changes include:
- Renamed set marking function to `mrb_gc_mark_set` and updated its
  return type to `size_t`.
- Introduced an explicit `mrb_gc_free_set` function for Set objects.
- Updated `gc_mark_children` to use the new mark function signature.
- Added an explicit `case MRB_TT_SET:` in `obj_free` to call `mrb_gc_free_set`.
- Adjusted `set_get_khash` in `mruby-set` to work with `MRB_TT_SET` directly,
  rather than relying on `mrb_data_get_ptr`.
- Corrected type checks in `set_init_copy` to use `MRB_TT_SET`.
- Updated function prototypes in internal headers and stubs in mrbc.
2025-06-24 04:02:41 +00:00
Yukihiro "Matz" Matsumoto 4e08fae75a mruby-compiler: add comprehensive comments to codegen.c 2025-06-24 09:50:37 +09:00
Yukihiro "Matz" Matsumoto 84a983c847 backtrace.c: add macros for clarity 2025-06-24 09:49:37 +09:00
Yukihiro Matz Matsumoto dcd661efb8 File.basename: add support for suffix removal and enhance tests 2025-06-23 22:49:43 +00:00
Yukihiro "Matz" Matsumoto 791b374155 khash.h: reduce KHASH_DEFAULT_SIZE from 32 to 8 2025-06-23 17:07:31 +09:00
Yukihiro "Matz" Matsumoto c152f3a79a mruby-set: add comprehensive tests for Set operations: +, -, & 2025-06-23 17:07:31 +09:00
Yukihiro "Matz" Matsumoto 18b45c7ab5 mruby-set: change string representation from #<Set: {1}> to Set[1] 2025-06-23 17:07:31 +09:00
Yukihiro "Matz" Matsumoto 561a3eac82 mruby-set: make eql? an alias of == method 2025-06-23 17:07:30 +09:00
Yukihiro "Matz" Matsumoto 20b32531ea mruby-set: Fix memory leak in Set#flatten! and simplify implementation
- Remove circular reference check in favor of max depth check only
- Fix memory leak by properly handling errors in set_flatten_bang
- Simplify code by reducing variables and unifying error handling
2025-06-23 17:07:30 +09:00
Yukihiro "Matz" Matsumoto 9d739cdad8 mruby-set: use set_is_set extensively 2025-06-23 17:07:30 +09:00
Yukihiro "Matz" Matsumoto f47609574a mruby-set: remove some AI generated work-log comments 2025-06-23 17:07:30 +09:00
Yukihiro "Matz" Matsumoto ea0ceff7fb mruby-set: implement Set#flatten and flatten! in C
The code is generated by Cursor.
2025-06-23 17:07:30 +09:00
Yukihiro "Matz" Matsumoto 73c61e4a60 mruby-set: optimize inspect/to_s to avoid intermediate array 2025-06-23 17:07:29 +09:00
Yukihiro "Matz" Matsumoto e2982bdb57 mruby-set: optimize join method to avoid intermediate array 2025-06-23 17:07:29 +09:00
Yukihiro "Matz" Matsumoto 0430f1e9b8 mruby-set: optimize eql? by checking fast path 2025-06-23 17:07:29 +09:00
Yukihiro "Matz" Matsumoto d7a0d5687e mruby-set: optimize equal by checking fast path 2025-06-23 17:07:29 +09:00
Yukihiro "Matz" Matsumoto 83fc43e71d mruby-set: improve Set#hash by using FNV-1 hashing 2025-06-23 17:07:29 +09:00
Yukihiro "Matz" Matsumoto 3a5d0a1840 mruby-set: simplify the code with KHASH_FOREACH macro 2025-06-23 17:07:28 +09:00
Yukihiro "Matz" Matsumoto eb1820d75e symbol.c: remove unused <mruby/khash.h> header 2025-06-23 17:07:28 +09:00
Yukihiro "Matz" Matsumoto e30ec3da42 mruby-metaprog: use KHASH_FOREACH macro 2025-06-23 17:07:28 +09:00
Yukihiro "Matz" Matsumoto bce8cee8f9 khash.h (KHASH_FOREACH): a new macro to iterate over khash table 2025-06-23 17:07:28 +09:00
Yukihiro "Matz" Matsumoto d41d477e22 mruby-set: add type checking helper functions
Add two helper functions to improve code clarity and maintainability:
- set_check_type: Checks if a value is a Set and raises an error if not
- set_is_set: Checks if a value is a Set and returns a boolean result

Update all relevant methods to use these helper functions, reducing
code duplication and centralizing type checking logic.
2025-06-23 17:07:27 +09:00
Yukihiro "Matz" Matsumoto deb5c47fc6 mruby-set: implement comparison methods in C for better performance
Reimplemented the following methods in C for improved efficiency:
- superset? and proper_superset? (>= and >)
- subset? and proper_subset? (<= and <)
- intersect? and disjoint?
- <=> comparison operator
2025-06-23 17:07:27 +09:00
Yukihiro "Matz" Matsumoto 60f06e7a0f mruby-set: Add comprehensive method documentation 2025-06-23 17:07:27 +09:00
Yukihiro "Matz" Matsumoto 091e48159a mruby-set: Use numbered parameters for block arguments 2025-06-23 17:07:27 +09:00
Yukihiro "Matz" Matsumoto 04b38c2c47 mruby-set: rename internal methods
Renaming all internal C methods from __set_* to a cleaner __* convention
(e.g., __set_merge is now __merge), and updating their call sites in the
Ruby code accordingly.
2025-06-23 17:07:26 +09:00
Yukihiro "Matz" Matsumoto e096eeed1a mruby-set: reimplement #initialize in Ruby again
And we have eliminated mrb_funcall* from set.c.
2025-06-23 17:07:26 +09:00
Yukihiro "Matz" Matsumoto 5e2a7568e2 mruby-set: move #replace to Ruby again
Since it does only clear() and merge(), there is little use of the C
implemented fast path. This change also reduce memory consumption.
2025-06-23 17:07:26 +09:00
Yukihiro "Matz" Matsumoto 100ba913f2 mruby-set: extensive refactor in set.c
We refactor out loop by set_khash_foreach() function, so that we don't
need to repeat for loop. it makes the code simpler. The code is written
by Atlassian Rovodev.
2025-06-23 17:07:26 +09:00
Yukihiro "Matz" Matsumoto f210772465 mruby-set: optimize Set operations to use mrb_get_arg1()
Replace mrb_get_args() with more efficient mrb_get_arg1() for
single-argument functions. The code is written by Atlassian Rovodev.
2025-06-23 17:07:26 +09:00
Yukihiro "Matz" Matsumoto c117674cfe mruby-set: refactor Set#replace
The code is written by Atlassian Rovodev.
2025-06-23 17:07:25 +09:00
Yukihiro "Matz" Matsumoto 8538c79f3f mruby-set: refactor Set#merge
The code is written by Atlassian Rovodev.
2025-06-23 17:07:25 +09:00
Yukihiro "Matz" Matsumoto 169654ad9b mruby-set: refactor Set#subtract
The code is written by Atlassian Rovodev.
2025-06-23 17:07:25 +09:00
Yukihiro "Matz" Matsumoto c188b9a1aa mruby-set: refactor Set#difference
The code is written by Atlassian Rovodev.
2025-06-23 17:07:25 +09:00