Skip to content

Commit 12c0445

Browse files
committed
refactor insn a little
1 parent d262eb6 commit 12c0445

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

insns.def

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -961,25 +961,32 @@ opt_string_new
961961
// The bookkeeping slot should be empty.
962962
RUBY_ASSERT(TOPN(argc + 1) == Qnil);
963963

964+
VALUE str = Qundef;
965+
964966
if (recv == rb_cString &&
965967
vm_method_cfunc_is(GET_CFP(), cd, recv, rb_class_new_instance_pass_kw) &&
966968
vm_cstr_initialize_basic_p(recv)) {
969+
967970
if (argc == 0) {
968-
// bare String.new: empty ASCII-8BIT string, same as the alloc func.
969-
VALUE str = rb_str_new(0, 0);
971+
str = rb_str_new(0, 0);
972+
}
973+
else {
974+
VALUE rbcapa = TOPN(capa_loc);
975+
if (FIXNUM_P(rbcapa)) {
976+
long capa = FIX2LONG(rbcapa);
977+
if (capa < 0) {
978+
capa = 0;
979+
}
980+
str = rb_str_new_capa_for_init(capa);
981+
}
982+
}
983+
984+
if (str != Qundef) {
970985
TOPN(argc) = str;
971986
TOPN(argc + 1) = str;
972987
}
973988
else {
974-
VALUE capa = TOPN(capa_loc);
975-
if (FIXNUM_P(capa)) {
976-
VALUE str = rb_str_new_capa_for_init(FIX2LONG(capa));
977-
TOPN(argc) = str;
978-
TOPN(argc + 1) = str;
979-
}
980-
else {
981-
JUMP(dst);
982-
}
989+
JUMP(dst);
983990
}
984991
}
985992
else {

0 commit comments

Comments
 (0)