mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
introduce ZALLOC{,_N} to replace ALLOC{,_N}+MEMZERO use
Using calloc where possible reduces code and binary sizes. * include/ruby/ruby.h (ZALLOC, ZALLOC_N): implement (Data_Make_Struct, TypedData_Make_Struct): ZALLOC replaces ALLOC+memset * compile.c (iseq_seq_sequence): ZALLOC_N replaces ALLOC_N+MEMZERO * cont.c (fiber_t_alloc): ZALLOC replaces ALLOC+MEMZERO * io.c (rb_io_reopen): ditto * iseq.c (prepare_iseq_build): ditto * parse.y (new_args_tail_gen, parser_new, ripper_s_allocate): ditto * re.c (match_alloc): ditto * variable.c (rb_const_set): ditto * ext/socket/raddrinfo.c (get_addrinfo): ditto * ext/strscan/strscan.c (strscan_s_allocate): ditto * gc.c (rb_objspace_alloc): calloc replaces malloc+MEMZERO git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5c094d381b
commit
48a2b96d2b
12 changed files with 33 additions and 30 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
Sat Jul 26 05:58:35 2014 Eric Wong <e@80x24.org>
|
||||
|
||||
* include/ruby/ruby.h (ZALLOC, ZALLOC_N): implement
|
||||
(Data_Make_Struct, TypedData_Make_Struct):
|
||||
ZALLOC replaces ALLOC+memset
|
||||
* compile.c (iseq_seq_sequence): ZALLOC_N replaces ALLOC_N+MEMZERO
|
||||
* cont.c (fiber_t_alloc): ZALLOC replaces ALLOC+MEMZERO
|
||||
* io.c (rb_io_reopen): ditto
|
||||
* iseq.c (prepare_iseq_build): ditto
|
||||
* parse.y (new_args_tail_gen, parser_new, ripper_s_allocate): ditto
|
||||
* re.c (match_alloc): ditto
|
||||
* variable.c (rb_const_set): ditto
|
||||
* ext/socket/raddrinfo.c (get_addrinfo): ditto
|
||||
* ext/strscan/strscan.c (strscan_s_allocate): ditto
|
||||
* gc.c (rb_objspace_alloc): calloc replaces malloc+MEMZERO
|
||||
|
||||
Sat Jul 26 05:54:54 2014 Eric Wong <e@80x24.org>
|
||||
|
||||
* symbol.c (dsymbol_check): remove unneeded semi-colon
|
||||
|
|
|
@ -1441,8 +1441,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
|
|||
/* make instruction sequence */
|
||||
generated_iseq = ALLOC_N(VALUE, pos);
|
||||
line_info_table = ALLOC_N(struct iseq_line_info_entry, k);
|
||||
iseq->is_entries = ALLOC_N(union iseq_inline_storage_entry, iseq->is_size);
|
||||
MEMZERO(iseq->is_entries, union iseq_inline_storage_entry, iseq->is_size);
|
||||
iseq->is_entries = ZALLOC_N(union iseq_inline_storage_entry, iseq->is_size);
|
||||
iseq->callinfo_entries = ALLOC_N(rb_call_info_t, iseq->callinfo_size);
|
||||
/* MEMZERO(iseq->callinfo_entries, rb_call_info_t, iseq->callinfo_size); */
|
||||
|
||||
|
|
3
cont.c
3
cont.c
|
@ -1162,8 +1162,7 @@ fiber_t_alloc(VALUE fibval)
|
|||
}
|
||||
|
||||
THREAD_MUST_BE_RUNNING(th);
|
||||
fib = ALLOC(rb_fiber_t);
|
||||
memset(fib, 0, sizeof(rb_fiber_t));
|
||||
fib = ZALLOC(rb_fiber_t);
|
||||
fib->cont.self = fibval;
|
||||
fib->cont.type = FIBER_CONTEXT;
|
||||
cont_init(&fib->cont, th);
|
||||
|
|
|
@ -718,8 +718,7 @@ get_addrinfo(VALUE self)
|
|||
static rb_addrinfo_t *
|
||||
alloc_addrinfo()
|
||||
{
|
||||
rb_addrinfo_t *rai = ALLOC(rb_addrinfo_t);
|
||||
memset(rai, 0, sizeof(rb_addrinfo_t));
|
||||
rb_addrinfo_t *rai = ZALLOC(rb_addrinfo_t);
|
||||
rai->inspectname = Qnil;
|
||||
rai->canonname = Qnil;
|
||||
return rai;
|
||||
|
|
|
@ -199,8 +199,7 @@ strscan_s_allocate(VALUE klass)
|
|||
{
|
||||
struct strscanner *p;
|
||||
|
||||
p = ALLOC(struct strscanner);
|
||||
MEMZERO(p, struct strscanner, 1);
|
||||
p = ZALLOC(struct strscanner);
|
||||
CLEAR_MATCH_STATUS(p);
|
||||
onig_region_init(&(p->regs));
|
||||
p->str = Qnil;
|
||||
|
|
6
gc.c
6
gc.c
|
@ -920,8 +920,7 @@ RVALUE_DEMOTE_FROM_OLD(rb_objspace_t *objspace, VALUE obj)
|
|||
rb_objspace_t *
|
||||
rb_objspace_alloc(void)
|
||||
{
|
||||
rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t));
|
||||
memset(objspace, 0, sizeof(*objspace));
|
||||
rb_objspace_t *objspace = calloc(1, sizeof(rb_objspace_t));
|
||||
ruby_gc_stress = ruby_initial_gc_stress;
|
||||
|
||||
malloc_limit = gc_params.malloc_limit_min;
|
||||
|
@ -1087,13 +1086,12 @@ heap_page_allocate(rb_objspace_t *objspace)
|
|||
}
|
||||
|
||||
/* assign heap_page entry */
|
||||
page = (struct heap_page *)malloc(sizeof(struct heap_page));
|
||||
page = (struct heap_page *)calloc(1, sizeof(struct heap_page));
|
||||
if (page == 0) {
|
||||
aligned_free(page_body);
|
||||
during_gc = 0;
|
||||
rb_memerror();
|
||||
}
|
||||
MEMZERO((void*)page, struct heap_page, 1);
|
||||
|
||||
page->body = page_body;
|
||||
|
||||
|
|
|
@ -1000,8 +1000,7 @@ void *rb_check_typeddata(VALUE, const rb_data_type_t *);
|
|||
rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))
|
||||
|
||||
#define Data_Make_Struct(klass,type,mark,free,sval) (\
|
||||
(sval) = ALLOC(type),\
|
||||
memset((sval), 0, sizeof(type)),\
|
||||
(sval) = ZALLOC(type),\
|
||||
Data_Wrap_Struct((klass),(mark),(free),(sval))\
|
||||
)
|
||||
|
||||
|
@ -1009,8 +1008,7 @@ void *rb_check_typeddata(VALUE, const rb_data_type_t *);
|
|||
rb_data_typed_object_alloc((klass),(sval),(data_type))
|
||||
|
||||
#define TypedData_Make_Struct(klass, type, data_type, sval) (\
|
||||
(sval) = ALLOC(type),\
|
||||
memset((sval), 0, sizeof(type)),\
|
||||
(sval) = ZALLOC(type),\
|
||||
TypedData_Wrap_Struct((klass),(data_type),(sval))\
|
||||
)
|
||||
|
||||
|
@ -1270,6 +1268,8 @@ rb_num2char_inline(VALUE x)
|
|||
|
||||
#define ALLOC_N(type,n) ((type*)xmalloc2((n),sizeof(type)))
|
||||
#define ALLOC(type) ((type*)xmalloc(sizeof(type)))
|
||||
#define ZALLOC_N(type,n) ((type*)xcalloc((n),sizeof(type)))
|
||||
#define ZALLOC(type) (ZALLOC_N(type,1))
|
||||
#define REALLOC_N(var,type,n) ((var)=(type*)xrealloc2((char*)(var),(n),sizeof(type)))
|
||||
|
||||
#define ALLOCA_N(type,n) ((type*)alloca(sizeof(type)*(n)))
|
||||
|
|
3
io.c
3
io.c
|
@ -6725,8 +6725,7 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
|
|||
rb_io_taint_check(file);
|
||||
fptr = RFILE(file)->fptr;
|
||||
if (!fptr) {
|
||||
fptr = RFILE(file)->fptr = ALLOC(rb_io_t);
|
||||
MEMZERO(fptr, rb_io_t, 1);
|
||||
fptr = RFILE(file)->fptr = ZALLOC(rb_io_t);
|
||||
}
|
||||
|
||||
if (!NIL_P(nmode) || !NIL_P(opt)) {
|
||||
|
|
3
iseq.c
3
iseq.c
|
@ -286,8 +286,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
|
|||
* iseq->cached_special_block = 0;
|
||||
*/
|
||||
|
||||
iseq->compile_data = ALLOC(struct iseq_compile_data);
|
||||
MEMZERO(iseq->compile_data, struct iseq_compile_data, 1);
|
||||
iseq->compile_data = ZALLOC(struct iseq_compile_data);
|
||||
RB_OBJ_WRITE(iseq->self, &iseq->compile_data->err_info, Qnil);
|
||||
RB_OBJ_WRITE(iseq->self, &iseq->compile_data->mark_ary, rb_ary_tmp_new(3));
|
||||
|
||||
|
|
9
parse.y
9
parse.y
|
@ -9511,8 +9511,7 @@ new_args_tail_gen(struct parser_params *parser, NODE *k, ID kr, ID b)
|
|||
NODE *node;
|
||||
int check = 0;
|
||||
|
||||
args = ALLOC(struct rb_args_info);
|
||||
MEMZERO(args, struct rb_args_info, 1);
|
||||
args = ZALLOC(struct rb_args_info);
|
||||
node = NEW_NODE(NODE_ARGS, 0, 0, args);
|
||||
|
||||
args->block_arg = b;
|
||||
|
@ -10244,8 +10243,7 @@ parser_new(void)
|
|||
{
|
||||
struct parser_params *p;
|
||||
|
||||
p = ALLOC_N(struct parser_params, 1);
|
||||
MEMZERO(p, struct parser_params, 1);
|
||||
p = ZALLOC(struct parser_params);
|
||||
parser_initialize(p);
|
||||
return p;
|
||||
}
|
||||
|
@ -10665,8 +10663,7 @@ ripper_s_allocate(VALUE klass)
|
|||
struct parser_params *p;
|
||||
VALUE self;
|
||||
|
||||
p = ALLOC_N(struct parser_params, 1);
|
||||
MEMZERO(p, struct parser_params, 1);
|
||||
p = ZALLOC(struct parser_params);
|
||||
self = TypedData_Wrap_Struct(klass, &parser_data_type, p);
|
||||
p->value = self;
|
||||
return self;
|
||||
|
|
3
re.c
3
re.c
|
@ -872,8 +872,7 @@ match_alloc(VALUE klass)
|
|||
match->str = 0;
|
||||
match->rmatch = 0;
|
||||
match->regexp = 0;
|
||||
match->rmatch = ALLOC(struct rmatch);
|
||||
MEMZERO(match->rmatch, struct rmatch, 1);
|
||||
match->rmatch = ZALLOC(struct rmatch);
|
||||
|
||||
return (VALUE)match;
|
||||
}
|
||||
|
|
|
@ -2213,8 +2213,7 @@ rb_const_set(VALUE klass, ID id, VALUE val)
|
|||
rb_clear_constant_cache();
|
||||
|
||||
|
||||
ce = ALLOC(rb_const_entry_t);
|
||||
MEMZERO(ce, rb_const_entry_t, 1);
|
||||
ce = ZALLOC(rb_const_entry_t);
|
||||
ce->flag = visibility;
|
||||
ce->line = rb_sourceline();
|
||||
st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce);
|
||||
|
|
Loading…
Add table
Reference in a new issue