rb_cstr2inum isn't very fast because it handles tons of different scenarios, and also require a NULL terminated string which forces us to copy the number into a secondary buffer.
But since the parser already computed the length, we can much more cheaply do this with a very simple function as long as the number is small enough to fit into a native type (long long).
If the number is too long, we can fallback to the rb_cstr2inum slowpath.
rb_cstr2inum
isn't very fast because it handles tons of different scenarios, and also require a NULL terminated string which forces us to copy the number into a secondary buffer.But since the parser already computed the length, we can much more cheaply do this with a very simple function as long as the number is small enough to fit into a native type (
long long
).If the number is too long, we can fallback to the
rb_cstr2inum
slowpath.Before:
After: