Project

General

Profile

Feature #10585 ยป 0001-struct.c-speedup-struct.name-v-for-small-structs.patch

funny_falcon (Yura Sokolov), 12/10/2014 02:31 PM

View differences:

struct.c
144 144
}
145 145

  
146 146
static VALUE
147
rb_struct_set(VALUE obj, long i, VALUE val)
148
{
149
    if (i >= RSTRUCT_LEN(obj)) {
150
	rb_raise(rb_eTypeError, "corrupted struct");
151
    }
152
    rb_struct_modify(obj);
153
    RSTRUCT_SET(obj, i, val);
154
    return val;
155
}
156

  
157
static VALUE rb_struct_set0(VALUE obj, VALUE val) {return rb_struct_set(obj, 0, val);}
158
static VALUE rb_struct_set1(VALUE obj, VALUE val) {return rb_struct_set(obj, 1, val);}
159
static VALUE rb_struct_set2(VALUE obj, VALUE val) {return rb_struct_set(obj, 2, val);}
160
static VALUE rb_struct_set3(VALUE obj, VALUE val) {return rb_struct_set(obj, 3, val);}
161
static VALUE rb_struct_set4(VALUE obj, VALUE val) {return rb_struct_set(obj, 4, val);}
162
static VALUE rb_struct_set5(VALUE obj, VALUE val) {return rb_struct_set(obj, 5, val);}
163
static VALUE rb_struct_set6(VALUE obj, VALUE val) {return rb_struct_set(obj, 6, val);}
164
static VALUE rb_struct_set7(VALUE obj, VALUE val) {return rb_struct_set(obj, 7, val);}
165
static VALUE rb_struct_set8(VALUE obj, VALUE val) {return rb_struct_set(obj, 8, val);}
166
static VALUE rb_struct_set9(VALUE obj, VALUE val) {return rb_struct_set(obj, 9, val);}
167

  
168
#define N_SET_FUNC numberof(ref_func)
169

  
170
static VALUE (*const set_func[])(VALUE, VALUE) = {
171
    rb_struct_set0,
172
    rb_struct_set1,
173
    rb_struct_set2,
174
    rb_struct_set3,
175
    rb_struct_set4,
176
    rb_struct_set5,
177
    rb_struct_set6,
178
    rb_struct_set7,
179
    rb_struct_set8,
180
    rb_struct_set9,
181
};
182

  
183
static VALUE
147 184
anonymous_struct(VALUE klass)
148 185
{
149 186
    VALUE nstr;
......
217 254
	else {
218 255
	    define_aref_method(nstr, ptr_members[i], off);
219 256
	}
220
	define_aset_method(nstr, ID2SYM(rb_id_attrset(id)), off);
257
	if (i < N_SET_FUNC) {
258
	    rb_define_method_id(nstr, rb_id_attrset(id), set_func[i], 1);
259
	}
260
	else {
261
	    define_aset_method(nstr, ID2SYM(rb_id_attrset(id)), off);
262
	}
221 263
    }
222 264

  
223 265
    return nstr;
224
-