mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
c14e26d79e
If the `Errno::EXXX` class is defined minimally when needed, it will save about 17 KiB of RAM in a 32-bit environment.
Define the singular methods `.const_defined?`, `.const_missing` and `.constants` in the `Errno` module and act as if there are classes that have not yet been defined.
However, if real classes are enumerated, for example by the following code, the effect is lost.
```ruby
Errno.constants.map { |id| Errno.const_get(id) }
```
But I believe that such codes are rarely written with the intention of being written.
In this patch, the `Errno::EXXX#initialize` method is no longer defined for further memory reduction.
Instead, it has been merged into the `SystemCallError#initialize` method.
16 lines
309 B
Ruby
16 lines
309 B
Ruby
module Errno
|
|
def Errno.const_defined?(name)
|
|
__errno_defined?(name) or super
|
|
end
|
|
|
|
def Errno.const_missing(name)
|
|
__errno_define(name) or super
|
|
end
|
|
|
|
# Module#constants is defined in mruby-metaprog
|
|
# So, it's may be raised NoMethodError
|
|
def Errno.constants
|
|
__errno_list(super)
|
|
end
|
|
end
|