The C API provides several features for optimizing method calls and things like directly accessing the length of a string via macro RSTRING_LEN() instead of going through the overhead of a Ruby method lookup.
Therefore, if the user can specify the type of a Ruby object using data types str, array and hsh. These Ruby objects will then be of that type only and assigning them to another type of Ruby object should raise an error (via calls to TYPE() etc.)
Sample code:
def foo
str a = "hello world"
return a.size
end
Since the compiler knows that a is a String, it can directly call RSTRING_LEN() to generate code like so:
// header code....
static VALUE foo(...)
{
VALUE a = rb_str_new2("hello world");
return INT2FIX(RSTRING_LEN(a));
}
// footer code....
Various such examples exist for each data type, all of which should be implemented.
The C API provides several features for optimizing method calls and things like directly accessing the length of a string via macro
RSTRING_LEN()
instead of going through the overhead of a Ruby method lookup.Therefore, if the user can specify the type of a Ruby object using data types
str
,array
andhsh
. These Ruby objects will then be of that type only and assigning them to another type of Ruby object should raise an error (via calls toTYPE()
etc.)Sample code:
Since the compiler knows that
a
is aString
, it can directly callRSTRING_LEN()
to generate code like so:Various such examples exist for each data type, all of which should be implemented.