Skip to content

Commit 31b74b1

Browse files
committed
Convert wrapping, unwrapping, and fast fixnum conversions to macros.
PullRequest: truffleruby/745
2 parents 6303a46 + cbf2ab2 commit 31b74b1

File tree

4 files changed

+4
-43
lines changed

4 files changed

+4
-43
lines changed

lib/cext/include/ruby/ruby.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ typedef char ruby_check_sizeof_voidp[SIZEOF_VOIDP == sizeof(void*) ? 1 : -1];
230230
#define FIXNUM_MAX RUBY_FIXNUM_MAX
231231
#define FIXNUM_MIN RUBY_FIXNUM_MIN
232232

233-
VALUE RB_INT2FIX(long value);
233+
#define RB_INT2FIX(i) (VALUE)rb_tr_wrap((long)(i))
234234
#define INT2FIX(i) RB_INT2FIX(i)
235-
VALUE RB_LONG2FIX(long value);
235+
#define RB_LONG2FIX(i) (VALUE)rb_tr_wrap((long)(i))
236236
#define LONG2FIX(i) RB_INT2FIX(i)
237237
#define rb_fix_new(v) RB_INT2FIX(v)
238238
VALUE rb_int2inum(intptr_t);

lib/cext/include/truffleruby/truffleruby-pre.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,8 @@ extern void* rb_tr_cext;
4545

4646
// Wrapping and unwrapping of values.
4747

48-
MUST_INLINE VALUE rb_tr_wrap(VALUE object) {
49-
return polyglot_invoke(RUBY_CEXT, "rb_tr_wrap", object);
50-
}
51-
52-
MUST_INLINE VALUE rb_tr_unwrap(VALUE object) {
53-
return polyglot_invoke(RUBY_CEXT, "rb_tr_unwrap", object);
54-
}
48+
#define rb_tr_wrap(object) polyglot_invoke(RUBY_CEXT, "rb_tr_wrap", object)
49+
#define rb_tr_unwrap(object) polyglot_invoke(RUBY_CEXT, "rb_tr_unwrap", object)
5550

5651
// Needed for GC guarding
5752

src/main/c/cext/ruby.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,6 @@ short rb_fix2short(VALUE value) {
342342
rb_tr_error("rb_num2ushort not implemented");
343343
}
344344

345-
VALUE RB_INT2FIX(long value) {
346-
return rb_tr_wrap(polyglot_invoke(RUBY_CEXT, "INT2FIX", value));
347-
}
348-
349-
VALUE RB_LONG2FIX(long value) {
350-
return rb_tr_wrap(polyglot_invoke(RUBY_CEXT, "LONG2FIX", value));
351-
}
352-
353345
long rb_fix2int(VALUE value) {
354346
return polyglot_as_i32(RUBY_CEXT_INVOKE_NO_WRAP("rb_fix2int", value));
355347
}

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,6 @@ private Object execute(TruffleObject receiver, Object[] args, Node executeNode,
199199

200200
}
201201

202-
// TODO (pitr-ch 14-Dec-2017): remove from java
203-
@CoreMethod(names = "INT2FIX", onSingleton = true, required = 1)
204-
public abstract static class INT2FIXNode extends CoreMethodArrayArgumentsNode {
205-
206-
@Specialization
207-
public int int2fix(int num) {
208-
return num;
209-
}
210-
211-
@Specialization
212-
public long int2fix(long num) {
213-
return num;
214-
}
215-
216-
}
217-
218202
@CoreMethod(names = "rb_ulong2num", onSingleton = true, required = 1)
219203
public abstract static class ULong2NumNode extends CoreMethodArrayArgumentsNode {
220204

@@ -442,16 +426,6 @@ public Object dbl2big(double num,
442426

443427
}
444428

445-
@CoreMethod(names = "LONG2FIX", onSingleton = true, required = 1)
446-
public abstract static class LONG2FIXNode extends CoreMethodArrayArgumentsNode {
447-
448-
@Specialization
449-
public long long2fix(long num) {
450-
return num;
451-
}
452-
453-
}
454-
455429
@CoreMethod(names = "rb_class_of", onSingleton = true, required = 1)
456430
public abstract static class RBClassOfNode extends CoreMethodArrayArgumentsNode {
457431

0 commit comments

Comments
 (0)