summaryrefslogtreecommitdiff
path: root/yjit_codegen.c
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2021-10-14 13:48:24 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:43 -0400
commit4cad89308027d56b984fec0f9c796637832fb258 (patch)
tree2e57cb60aeb6930b135722837e5b4f340d63eebe /yjit_codegen.c
parent5d2e5218f643917e3add702e48ebe48ce7cb80ba (diff)
Add String#bytesize
Fixes: https://github.com/Shopify/yjit/issues/258 Co-authored-by: Aaron Patterson tenderlove@ruby-lang.org
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r--yjit_codegen.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c
index b3ab3e014f..611a20226f 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -3029,6 +3029,27 @@ jit_rb_obj_equal(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, cons
return true;
}
+static VALUE
+yjit_str_bytesize(VALUE str)
+{
+ return LONG2NUM(RSTRING_LEN(str));
+}
+
+static bool
+jit_rb_str_bytesize(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const rb_callable_method_entry_t *cme, rb_iseq_t *block, const int32_t argc, VALUE *known_recv_klass)
+{
+ ADD_COMMENT(cb, "String#bytesize");
+
+ x86opnd_t recv = ctx_stack_pop(ctx, 1);
+ mov(cb, C_ARG_REGS[0], recv);
+ call_ptr(cb, REG0, (void *)&yjit_str_bytesize);
+
+ x86opnd_t out_opnd = ctx_stack_push(ctx, TYPE_FIXNUM);
+ mov(cb, out_opnd, RAX);
+
+ return true;
+}
+
// Codegen for rb_str_to_s()
// When String#to_s is called on a String instance, the method returns self and
// most of the overhead comes from setting up the method call. We observed that
@@ -4667,6 +4688,7 @@ yjit_init_codegen(void)
// rb_str_to_s() methods in string.c
yjit_reg_method(rb_cString, "to_s", jit_rb_str_to_s);
yjit_reg_method(rb_cString, "to_str", jit_rb_str_to_s);
+ yjit_reg_method(rb_cString, "bytesize", jit_rb_str_bytesize);
// Thread.current
yjit_reg_method(rb_singleton_class(rb_cThread), "current", jit_thread_s_current);