ruby-changes:58836
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 19 Nov 2019 12:36:41 +0900 (JST)
Subject: [ruby-changes:58836] 0e8219f591 (master): make functions static
https://git.ruby-lang.org/ruby.git/commit/?id=0e8219f591 From 0e8219f591f3f17cb7ee361e8a60dbef08145883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= <shyouhei@r...> Date: Mon, 18 Nov 2019 12:13:08 +0900 Subject: make functions static These functions are used from within a compilation unit so we can make them static, for better binary size. This changeset reduces the size of generated ruby binary from 26,590,128 bytes to 26,584,472 bytes on my macihne. diff --git a/array.c b/array.c index e3bbef6..28bd8c8 100644 --- a/array.c +++ b/array.c @@ -1532,6 +1532,8 @@ rb_ary_subseq(VALUE ary, long beg, long len) https://github.com/ruby/ruby/blob/trunk/array.c#L1532 return ary_make_partial(ary, klass, beg, len); } +static VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e); + /* * call-seq: * ary[index] -> obj or nil diff --git a/bignum.c b/bignum.c index 0539232..4569183 100644 --- a/bignum.c +++ b/bignum.c @@ -3990,6 +3990,8 @@ str2big_gmp( https://github.com/ruby/ruby/blob/trunk/bignum.c#L3990 } #endif +static VALUE rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base); + /* * Parse +str+ as Ruby Integer, i.e., underscores, 0d and 0b prefixes. * @@ -4233,7 +4235,7 @@ rb_int_parse_cstr(const char *str, ssize_t len, char **endp, size_t *ndigits, https://github.com/ruby/ruby/blob/trunk/bignum.c#L4235 return bignorm(z); } -VALUE +static VALUE rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base) { return rb_int_parse_cstr(str, len, endp, NULL, base, diff --git a/compile.c b/compile.c index 3cf5bb6..b73b985 100644 --- a/compile.c +++ b/compile.c @@ -755,7 +755,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L755 return iseq_setup(iseq, ret); } -int +static int rb_iseq_translate_threaded_code(rb_iseq_t *iseq) { #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE diff --git a/error.c b/error.c index 0859036..13d1910 100644 --- a/error.c +++ b/error.c @@ -159,7 +159,7 @@ rb_warning_s_warn(VALUE mod, VALUE str) https://github.com/ruby/ruby/blob/trunk/error.c#L159 * printing the warning to $stderr. */ -VALUE +static VALUE rb_warning_warn(VALUE mod, VALUE str) { return rb_funcallv(mod, id_warn, 1, &str); @@ -1169,6 +1169,8 @@ exc_backtrace(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L1169 return obj; } +static VALUE rb_check_backtrace(VALUE); + VALUE rb_get_backtrace(VALUE exc) { @@ -1212,7 +1214,7 @@ exc_backtrace_locations(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L1214 return obj; } -VALUE +static VALUE rb_check_backtrace(VALUE bt) { long i; @@ -1506,6 +1508,8 @@ name_err_initialize(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/error.c#L1508 return self; } +static VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method); + static VALUE name_err_init(VALUE exc, VALUE mesg, VALUE recv, VALUE method) { @@ -1636,7 +1640,7 @@ static const rb_data_type_t name_err_mesg_data_type = { https://github.com/ruby/ruby/blob/trunk/error.c#L1640 }; /* :nodoc: */ -VALUE +static VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method) { VALUE result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, 0); diff --git a/gc.c b/gc.c index 7803bac..899ca6b 100644 --- a/gc.c +++ b/gc.c @@ -1747,6 +1747,8 @@ heap_unlink_page(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *pag https://github.com/ruby/ruby/blob/trunk/gc.c#L1747 heap->total_slots -= page->total_slots; } +static void rb_aligned_free(void *ptr); + static void heap_page_free(rb_objspace_t *objspace, struct heap_page *page) { @@ -2302,7 +2304,7 @@ rb_imemo_tmpbuf_new(VALUE v1, VALUE v2, VALUE v3, VALUE v0) https://github.com/ruby/ruby/blob/trunk/gc.c#L2304 return newobj_of(v0, flags, v1, v2, v3, FALSE); } -VALUE +static VALUE rb_imemo_tmpbuf_auto_free_maybe_mark_buffer(void *buf, size_t cnt) { return rb_imemo_tmpbuf_new((VALUE)buf, 0, (VALUE)cnt, 0); @@ -9624,7 +9626,7 @@ rb_aligned_malloc(size_t alignment, size_t size) https://github.com/ruby/ruby/blob/trunk/gc.c#L9626 return res; } -void +static void rb_aligned_free(void *ptr) { #if defined __MINGW32__ diff --git a/hash.c b/hash.c index ab9af76..84ab343 100644 --- a/hash.c +++ b/hash.c @@ -146,7 +146,7 @@ rb_hash(VALUE obj) https://github.com/ruby/ruby/blob/trunk/hash.c#L146 return hval; } -long rb_objid_hash(st_index_t index); +static long rb_objid_hash(st_index_t index); static st_index_t dbl_to_index(double d) @@ -264,7 +264,7 @@ key64_hash(uint64_t key, uint32_t seed) https://github.com/ruby/ruby/blob/trunk/hash.c#L264 /* Should cast down the result for each purpose */ #define st_index_hash(index) key64_hash(rb_hash_start(index), prime2) -long +static long rb_objid_hash(st_index_t index) { return (long)st_index_hash(index); @@ -4153,6 +4153,8 @@ rb_hash_compact_bang(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L4153 return Qnil; } +static st_table *rb_init_identtable_with_size(st_index_t size); + /* * call-seq: * hsh.compare_by_identity -> hsh @@ -4227,7 +4229,7 @@ rb_init_identtable(void) https://github.com/ruby/ruby/blob/trunk/hash.c#L4229 return st_init_table(&identhash); } -st_table * +static st_table * rb_init_identtable_with_size(st_index_t size) { return st_init_table_with_size(&identhash, size); diff --git a/internal.h b/internal.h index 3cfb5a4..79c4fd6 100644 --- a/internal.h +++ b/internal.h @@ -1206,7 +1206,6 @@ typedef struct rb_imemo_tmpbuf_struct { https://github.com/ruby/ruby/blob/trunk/internal.h#L1206 } rb_imemo_tmpbuf_t; #define rb_imemo_tmpbuf_auto_free_pointer() rb_imemo_new(imemo_tmpbuf, 0, 0, 0, 0) -VALUE rb_imemo_tmpbuf_auto_free_maybe_mark_buffer(void *buf, size_t cnt); rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt); #define RB_IMEMO_TMPBUF_PTR(v) \ @@ -1364,7 +1363,6 @@ void rb_ary_delete_same(VALUE, VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1363 VALUE rb_ary_tmp_new_fill(long capa); VALUE rb_ary_at(VALUE, VALUE); VALUE rb_ary_aref1(VALUE ary, VALUE i); -VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e); size_t rb_ary_memsize(VALUE); VALUE rb_to_array_type(VALUE obj); VALUE rb_check_to_array(VALUE ary); @@ -1425,7 +1423,6 @@ VALUE rb_big_even_p(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1423 size_t rb_big_size(VALUE); VALUE rb_integer_float_cmp(VALUE x, VALUE y); VALUE rb_integer_float_eq(VALUE x, VALUE y); -VALUE rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base); VALUE rb_str_convert_to_inum(VALUE str, int base, int badcheck, int raise_exception); VALUE rb_big_comp(VALUE x); VALUE rb_big_aref(VALUE x, VALUE y); @@ -1516,7 +1513,6 @@ extern VALUE rb_eEAGAIN; https://github.com/ruby/ruby/blob/trunk/internal.h#L1513 extern VALUE rb_eEWOULDBLOCK; extern VALUE rb_eEINPROGRESS; void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args); -VALUE rb_check_backtrace(VALUE); NORETURN(void rb_async_bug_errno(const char *,int)); const char *rb_builtin_type_name(int t); const char *rb_builtin_class_name(VALUE x); @@ -1541,7 +1537,6 @@ VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int https://github.com/ruby/ruby/blob/trunk/internal.h#L1537 VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE name); #define rb_key_err_raise(mesg, recv, name) \ rb_exc_raise(rb_key_err_new(mesg, recv, name)) -VALUE rb_warning_warn(VALUE mod, VALUE str); PRINTF_ARGS(VALUE rb_warning_string(const char *fmt, ...), 1, 2); NORETURN(void rb_vraise(VALUE, const char *, va_list)); @@ -1635,7 +1630,6 @@ __attribute__((__alloc_align__(1))) https://github.com/ruby/ruby/blob/trunk/internal.h#L1630 #endif #endif void *rb_aligned_malloc(size_t, size_t) RUBY_ATTR_MALLOC RUBY_ATTR_ALLOC_SIZE((2)); -void rb_aligned_free(void *); size_t rb_size_mul_or_raise(size_t, size_t, VALUE); /* used in compile.c */ size_t rb_size_mul_add_or_raise(size_t, size_t, size_t, VALUE); /* used in iseq.h */ @@ -1657,10 +1651,8 @@ VALUE rb_hash_new_with_size(st_index_t size); https://github.com/ruby/ruby/blob/trunk/internal.h#L1651 VALUE rb_hash_has_key(VALUE hash, VALUE key); VALUE rb_hash_default_value(VALUE hash, VALUE key); VALUE rb_hash_set_default_proc(VALUE hash, VALUE proc); -long rb_objid_hash(st_index_t index); long rb_dbl_long_hash(double d); st_table *rb_init_identtable(void); -st_table *rb_init_identtable_with_size(st_index_t size); VALUE rb_hash_compare_by_id_p(VALUE hash); VALUE rb_to_hash_type(VALUE obj); VALUE rb_hash_key_str(VALUE); @@ -1714,7 +1706,6 @@ VALUE rb_math_hypot(VALUE, VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1706 VALUE rb_math_log(int argc, const VALUE *argv); VALUE rb_math_sin(VALUE); VALUE rb_math_sinh(VALUE); -VALUE rb_math_sqrt(VALUE); /* mjit.c */ @@ -1768,7 +1759,6 @@ int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl, int allow_endles https://github.com/ruby/ruby/blob/trunk/internal.h#L1759 double ruby_float_mod(double x, double y); int rb_num_negative_p(VALUE); VALUE rb_int_succ(VALUE num); -VALUE rb_int_pred(VALUE num); VALUE rb_int_uminus(VALUE num); VALUE rb_float_uminus(VALUE num); VALUE rb_int_plus(VALUE x, VALUE y); @@ -1779,9 +1769,7 @@ VALUE rb_float_mul(VALUE x, VALUE y); https://github.com/ruby/ruby/blob/trunk/internal.h#L1769 VALUE rb_float_div(VALUE x, VALUE y); VALUE rb_int_idiv(VALUE x, VALUE y); VALUE rb_int_modulo(VALUE x, VALUE y); -VALUE rb_int_round(VALUE num, int ndigits, enum ruby_num_rounding_mode mode); VALUE rb_int2str(VALUE num, int base); -VALUE rb_dbl_hash(double d); VALUE rb_fix_plus(VALUE x, VALUE y); VALUE rb_fix_aref(VALUE fix, VALUE idx); VALUE rb_int_gt(VALUE x, VALUE y); @@ -2280,7 +2268,6 @@ VALUE rb_check_funcall_with_hook_ (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/