mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
class.c: use tombstone for remove_method with ROM method tables
Previously, removing a ROM method required flattening all chain layers into a single mutable table. This was O(n) and allocated RAM for all previously-ROM methods. Use a tombstone marker (MT_FUNC flag with func=NULL) instead. The mt_get() lookup treats this as "not found" and stops the chain walk, hiding the ROM entry while allowing superclass lookup. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,13 @@ typedef struct mt_tbl {
|
||||
#define MT_PUBLIC 0 /* MRB_METHOD_PUBLIC_FL */
|
||||
#define MT_PRIVATE 1 /* MRB_METHOD_PRIVATE_FL */
|
||||
|
||||
/* "removed" tombstone: MT_FUNC flag set with NULL function pointer.
|
||||
This combination never occurs naturally (C functions are never NULL).
|
||||
Unlike undef (proc=NULL without MT_FUNC), a removed marker makes
|
||||
mt_get() return 0 ("not found"), blocking ROM chain walk while
|
||||
allowing superclass lookup. */
|
||||
#define MT_REMOVED_P(key, val) (((key)&MT_FUNC) && (val).func==NULL)
|
||||
|
||||
void mrb_mt_init_rom(struct RClass *c, mt_tbl *rom);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user