Method: MatchData#initialize_copy

Defined in:
re.c

#initialize_copy(orig) ⇒ Object

:nodoc:



1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
# File 're.c', line 1088

static VALUE
match_init_copy(VALUE obj, VALUE orig)
{
    rb_matchext_t *rm;

    if (!OBJ_INIT_COPY(obj, orig)) return obj;

    RB_OBJ_WRITE(obj, &RMATCH(obj)->str, RMATCH(orig)->str);
    RB_OBJ_WRITE(obj, &RMATCH(obj)->regexp, RMATCH(orig)->regexp);

    rm = RMATCH_EXT(obj);
    if (rb_reg_region_copy(&rm->regs, RMATCH_REGS(orig)))
        rb_memerror();

    if (RMATCH_EXT(orig)->char_offset_num_allocated) {
        if (rm->char_offset_num_allocated < rm->regs.num_regs) {
            REALLOC_N(rm->char_offset, struct rmatch_offset, rm->regs.num_regs);
            rm->char_offset_num_allocated = rm->regs.num_regs;
        }
        MEMCPY(rm->char_offset, RMATCH_EXT(orig)->char_offset,
               struct rmatch_offset, rm->regs.num_regs);
        RB_GC_GUARD(orig);
    }

    return obj;
}