google-labs-jules[bot]
8a91c91a69
Improve method table performance by rehashing at 75% load factor.
...
The method table (mt_tbl) in src/class.c previously only rehashed when it became completely full. With linear probing, this could lead to significant performance degradation for lookups and insertions as the table approached full capacity.
This change introduces a load factor (MT_LOAD_FACTOR_NUM/MT_LOAD_FACTOR_DEN, set to 3/4 or 0.75). The mt_put function now checks if adding a new element would cause the table's size to meet or exceed this load factor relative to its allocated capacity. If so, it triggers a rehash before inserting the new element.
This helps maintain more empty slots in the hash table, improving the average-case performance of linear probing and reducing the likelihood of worst-case scenarios. The existing initial allocation size and doubling strategy for rehashing are retained.
2025-05-24 22:50:29 +00:00
dearblue
36df859333
Revert "class.c (find_visibility_scope): when callinfo returns, *ep == NULL; #6512 "
...
This reverts commit 3879b95a62 .
This is because the code first reported in #6494 no longer works.
2025-05-18 18:52:32 +09:00
Yukihiro "Matz" Matsumoto
6766fcb905
class.c (mt_rehash): Fix mrb_calloc argument order
...
Since mrb_calloc() (along with mrb_calloc) takes two arguments: nmemb
which is number of array elements, and size which is size of the array.
Of course, revsersing does not change the behavior, but we'd like to
respect the original design intention of calloc(3).
2025-05-11 20:11:56 +09:00
Yukihiro "Matz" Matsumoto
3879b95a62
class.c (find_visibility_scope): when callinfo returns, *ep == NULL; #6512
2025-05-08 12:02:32 +09:00
Yukihiro "Matz" Matsumoto
2b0d866da1
class.c (find_visibility_scope): rename the function; ref #6512
...
Since the function returns either callinfo or env, thus the name does
not describe the current behavior. In addition, we did some refactoring
on the function.
2025-05-08 12:02:00 +09:00
Yukihiro "Matz" Matsumoto
50c8e180d8
class.c (find_visibility_ci): refactor to reduce complexity; ref #6512
2025-05-08 07:57:35 +09:00
Yukihiro "Matz" Matsumoto
dbc4768758
mruby/internal.h: rename visibility separation macros; ref #6512
2025-05-08 07:32:36 +09:00
Yukihiro "Matz" Matsumoto
aec8d0c58b
Merge branch 'visibility' of github.com:dearblue/mruby into dearblue-visibility
2025-05-07 15:37:08 +09:00
Yukihiro "Matz" Matsumoto
b5ad35d8ef
proc.h (MRB_SET_VISIBILITY_FLAGS): rename macro
2025-05-07 12:19:04 +09:00
Yukihiro "Matz" Matsumoto
1bc16676a1
class.c: implement BasicObject#!= in C file
...
The method is defined in inline bytecode. As a side-effect, `00class.rb`
was removed.
2025-05-01 10:23:03 +09:00
Yukihiro "Matz" Matsumoto
08f74dd2be
class.c: move alias attr attr_reader from 00class.rb
2025-04-28 14:20:07 +09:00
Yukihiro "Matz" Matsumoto
6c72f8b378
class.c (extend_object): remove method; implement Kernel#extend in C
2025-04-28 10:30:00 +09:00
Yukihiro "Matz" Matsumoto
6c25b5896a
class.c (prepend_features): remove the method
...
Just like `#append_features`, we remove `#prepend_features` and
implemented `#prepend` directly in C.
2025-04-28 10:30:00 +09:00
Yukihiro "Matz" Matsumoto
9387cd382e
class.c (append_features): remove the method
...
The technique is called "double dispatch" (that was popular in
Smalltalk), but it does not work well with mruby. It's slower and
consumes more memory. Even thought `#append_features` defined in ISO
standard (15.2.2.4.11), we decided to remove it. Strictly speaking, it
is mruby limitation. And it should be documented clearly.
2025-04-28 10:30:00 +09:00
Yukihiro "Matz" Matsumoto
e5478c2b40
class.c (setup_class): simplified using mrb_const_set()
2025-04-25 16:23:02 +09:00
Yukihiro "Matz" Matsumoto
03719490eb
class.c: define const_added method (with empty body)
2025-04-25 15:56:57 +09:00
dearblue
3fd5e1c250
Fixed visibility at method definition
...
There was a problem with visibility state from proc that straddles a fiber or is independent.
Therefore, it has been changed to give priority to env objects, if any.
Also, added "separate module" flag to block traversal to a higher level env object.
Note that the "separate module" flag is now set when calling blocks with the `mrb_yield_with_class()` function.
fixed https://github.com/mruby/mruby/issues/6494
2025-04-11 21:36:26 +09:00
dearblue
84e1b0045c
Fixed class method visibility via module_function
...
The following code should work
```ruby
module M
def me
p self
end
module_function :me
end
M.me
```
2025-04-07 21:40:56 +09:00
Yukihiro "Matz" Matsumoto
1e6442f54e
Revert "class.c (include_module_at): narrow local variable scope"
...
C++ does not compile `goto` cross local variable declaration.
This reverts commit c618b44fee .
2025-03-10 19:33:49 +09:00
Yukihiro "Matz" Matsumoto
1e36d7662c
object.h: rename gccolor to clearer gc_color
2025-03-10 14:23:51 +09:00
Yukihiro "Matz" Matsumoto
c618b44fee
class.c (include_module_at): narrow local variable scope
2025-03-10 11:26:13 +09:00
Yukihiro "Matz" Matsumoto
48f93adcdc
class.c (boot_defclass): unify variable declaration and initialization
2025-03-10 11:25:34 +09:00
Yukihiro "Matz" Matsumoto
436269f62c
class.c: remove duplicated CI_TARGET_CLASS definition from class.c
2025-03-08 11:09:57 +09:00
Yukihiro "Matz" Matsumoto
3c4f6501b0
class.c (find_visibility_ci): inline find_ci_from_proc()
2025-03-08 07:54:51 +09:00
Yukihiro "Matz" Matsumoto
ec7477fe0d
class.c: take visibility from outer scope
...
It is possible to update the visibility from within a block, so that
`find_visibility_ci()` should look up outer scopes.
2025-03-07 17:49:08 +09:00
Yukihiro "Matz" Matsumoto
889f09f8b7
class.c: move visibility flags from classes/modules to callinfo
2025-03-07 17:17:50 +09:00
Yukihiro "Matz" Matsumoto
6e1ab49ed3
class.c: allow changing visibility of methods defined in superclasses
2025-03-07 17:17:49 +09:00
Yukihiro "Matz" Matsumoto
37fb59bdac
class.h: rename macros for clarity
...
- MRB_SET_VISIBILITY -> MRB_CLASS_SET_VISIBILITY
- MRB_VISIBILITY -> MRB_CLASS_VISIBILITY
2025-03-07 17:17:49 +09:00
Yukihiro "Matz" Matsumoto
2a876d2047
class.c: implement top-level public/private/protected in the core in C
2025-03-07 17:17:49 +09:00
Yukihiro "Matz" Matsumoto
43da490a1e
class.c: alias should keep the visibility of the original
2025-03-07 17:17:48 +09:00
Yukihiro "Matz" Matsumoto
921d632615
class.c (mrb_mod_visibility): clear method cache
2025-03-07 17:17:48 +09:00
Yukihiro "Matz" Matsumoto
20d5330417
class.c: use MT_VMASK to mask the flag values
2025-03-07 17:17:48 +09:00
Yukihiro "Matz" Matsumoto
aba9a7d053
class.c: #initialize should be private by default
...
Fixed wrong condition.
2025-03-07 17:17:46 +09:00
Yukihiro "Matz" Matsumoto
cfc104e66c
class.c (mrb_define_module_function): make instance method private
2025-03-07 17:17:42 +09:00
Yukihiro "Matz" Matsumoto
4122cee9e4
class.c: implement attr_accessor in C
2025-03-07 17:17:39 +09:00
Yukihiro "Matz" Matsumoto
7d2beb9fef
class.c (mrb_remove_method): should call hook method from the origin
...
MRB_CLASS_ORIGIN moves the pointer for prepended class/module, but the
hook method should be searched from the original class/module.
2025-03-07 17:17:38 +09:00
Yukihiro "Matz" Matsumoto
6168b15e0e
class.c (undef_method): call hook method when undef'ing a method
2025-03-07 17:17:38 +09:00
Yukihiro "Matz" Matsumoto
bcd0e0e439
class.c (mrb_remove_method): call hook method
...
Depending the context, hook method should be either method_removed or
singleton_method_removed.
2025-03-07 17:17:38 +09:00
Yukihiro "Matz" Matsumoto
0863c08841
class.c: implement singleton method hook methods
...
- singleton_method_removed
- singleton_method_undefined
2025-03-07 17:17:37 +09:00
Yukihiro "Matz" Matsumoto
9c74f6e908
class.c: implement method hook methods
...
- method_removed
- method_undefined
2025-03-07 17:17:37 +09:00
Yukihiro "Matz" Matsumoto
eb8b4120d7
class.c: initialize method needs to be private by default
2025-03-07 17:17:37 +09:00
Yukihiro "Matz" Matsumoto
e660e28a39
class.c: make some Module methods private
...
- append_features
- extend_object
- extended
- included
- initialize
- method_added
- module_function
- prepend_features
- prepended
- private
- protected
- public
- remove_const
2025-03-07 17:17:36 +09:00
Yukihiro "Matz" Matsumoto
f5150ab98a
class.c: make some Class methods private
...
- initialize
- inherited
2025-03-07 17:17:36 +09:00
Yukihiro "Matz" Matsumoto
c5e270e8f3
class.c: make some BasicObject methods private
...
- initialize
- singleton_method_added
- method_missing
2025-03-07 17:17:36 +09:00
Yukihiro "Matz" Matsumoto
ca20017ac9
class.c: implement mrb_define_private_method()
2025-03-07 17:17:36 +09:00
Yukihiro "Matz" Matsumoto
71c0de7f08
class.c (mrb_define_method_raw): take visibility from the class
...
If not explicitly specified in the method struct.
2025-03-07 17:17:36 +09:00
Yukihiro "Matz" Matsumoto
fdf71d8f2d
class.c: first step to private methods; #1835
...
Now each method entry holds visibility information in flag bits.
2025-03-07 17:17:34 +09:00
dearblue
b86c220384
Avoid array object creation with “unknown keyword” error
...
It is sufficient to return the first element.
2025-02-02 21:02:03 +09:00
dearblue
a981f5aed7
Add more const qualifier for RProc
2025-01-20 22:25:50 +09:00
Yukihiro "Matz" Matsumoto
8276143f03
object.h: remove MRB_SET_FROZEN_FLAG/MRB_UNSET_FROZEN_FLAG macros
...
Simple `o->frozen = 1/0` now works.
2025-01-07 13:56:30 +09:00