Skip to content

Commit 26cc873

Browse files
committed
Directly return a native pointer for RSTRING_PTR() if the String is already native
* 110s => 64s for a small `bundle install`. (cherry picked from commit 190cf34)
1 parent 5fddc14 commit 26cc873

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/c/cext/ruby.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,11 @@ char *rb_string_value_cstr(VALUE *value_pointer) {
812812
}
813813

814814
char *RSTRING_PTR_IMPL(VALUE string) {
815-
return (char *)polyglot_as_i8_array(RUBY_CEXT_INVOKE_NO_WRAP("RSTRING_PTR", string));
815+
if (polyglot_as_boolean(RUBY_CEXT_INVOKE_NO_WRAP("native_string?", string))) {
816+
return NATIVE_RSTRING_PTR(string);
817+
} else {
818+
return (char *)polyglot_as_i8_array(RUBY_CEXT_INVOKE_NO_WRAP("RSTRING_PTR", string));
819+
}
816820
}
817821

818822
char *RSTRING_END(VALUE string) {

0 commit comments

Comments
 (0)