summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-25 21:34:35 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-25 21:34:35 +0000
commit48a2b96d2b8228a1c7dd49425fccd8b1202bf905 (patch)
tree2b584a1e13e292481269507051d79bf6358e3257 /include
parent5c094d381bca5d244495a7f4a94572c1f4562c28 (diff)
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
Diffstat (limited to 'include')
-rw-r--r--include/ruby/ruby.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 7bb322868e..472e1e417a 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -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)))