Skip to content

Commit 804ce37

Browse files
committed
Immediately go to native for RSTRING_PTR()
* That is, use RSTRING_PTR() as a hint the C extension is going to access the byte with native memory accesses. * Adapt RSTRING_PTR() spec since it always goes native directly now. * 64s => 59s for a small `bundle install`. (cherry picked from commit 9a22abd)
1 parent 26cc873 commit 804ce37

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

spec/truffle/capi/string_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
@s = CApiTruffleStringSpecs.new
1616
end
1717

18-
it "does not store the String to native memory if not needed" do
18+
it "stores the String to native memory even if not needed for efficiency" do
1919
str = "foobar"
2020
@s.string_ptr(str).should == "f"
21-
Truffle::CExt.native_string?(str).should == false
21+
Truffle::CExt.native_string?(str).should == true
2222
end
2323

2424
it "stores the String to native memory if the address is returned" do

src/main/c/cext/ruby.c

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

814814
char *RSTRING_PTR_IMPL(VALUE 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-
}
815+
return NATIVE_RSTRING_PTR(string);
820816
}
821817

822818
char *RSTRING_END(VALUE string) {

0 commit comments

Comments
 (0)