Skip to content

Commit dc27f35

Browse files
committed
[GR-17457] Remove overhead when using RDATA_PTR.
PullRequest: truffleruby/3238
2 parents ccc9eb9 + 811b16b commit dc27f35

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Performance:
5656
* Rewrote `ArrayEachIteratorNode` to optimize performance for a constant-sized array and reduce specializations to 1 general case (#2587, @MattAlp)
5757
* Reduce conversion of `VALUE`s to native handle during common operations in C extensions (@aardvark179).
5858
* Improved performance of regex boolean matches (e.g., `Regexp#match?`) by avoiding match data allocation in TRegex (#2558, @nirvdrum).
59+
* Remove overhead when getting using `RDATA_PTR` (@aardvark179).
5960

6061
Changes:
6162

lib/cext/ABI_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13
1+
14

lib/cext/include/ruby/internal/core/rdata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static inline void *
138138
rb_data_object_get(VALUE obj)
139139
{
140140
#ifdef TRUFFLERUBY
141-
return DATA_PTR(obj);
141+
return polyglot_invoke(RUBY_CEXT, "RDATA_PTR", rb_tr_unwrap(obj));
142142
#else
143143
Check_Type(obj, RUBY_T_DATA);
144144
return DATA_PTR(obj);

lib/truffle/truffle/cext_structs.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ def RDATA(object)
2222
RData.new(object, data_holder)
2323
end
2424

25+
def RDATA_PTR(object)
26+
# A specialized version of rb_check_type(object, T_DATA)
27+
data_holder = Primitive.object_hidden_var_get(object, DATA_HOLDER)
28+
unless data_holder
29+
raise TypeError, "wrong argument type #{object.class} (expected T_DATA)"
30+
end
31+
32+
data_holder.data
33+
end
34+
2535
def RBASIC(object)
2636
if Primitive.immediate_value?(object)
2737
raise TypeError, "immediate values don't include the RBasic struct"

0 commit comments

Comments
 (0)