ruby-changes:49345
From: nobu <ko1@a...>
Date: Mon, 25 Dec 2017 11:42:19 +0900 (JST)
Subject: [ruby-changes:49345] nobu:r61460 (trunk): prelude.c.tmpl: static literals
nobu 2017-12-25 11:42:13 +0900 (Mon, 25 Dec 2017) New Revision: 61460 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61460 Log: prelude.c.tmpl: static literals * template/prelude.c.tmpl (PRELUDE_STR): make string objects with static literals not to copy them. Modified files: trunk/template/prelude.c.tmpl Index: template/prelude.c.tmpl =================================================================== --- template/prelude.c.tmpl (revision 61459) +++ template/prelude.c.tmpl (revision 61460) @@ -85,7 +85,10 @@ Prelude.new(output && output[/\w+(?=_pre https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L85 % preludes = @preludes.values.sort % preludes.each {|i, prelude, lines, sub| -static const char prelude_name<%=i%><%=%>[] = "<%=c_esc(prelude_name(*prelude))%>"; +% name = prelude_name(*prelude) +static const struct { + char L0[<%=name.size%><%=%>]; +} prelude_name<%=i%><%=%> = {"<%=c_esc(name)%>"}; static const struct { % size = beg = 0 % lines.each_with_index {|(line, comment), n| @@ -135,6 +138,7 @@ prelude_prefix_path(VALUE self) https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L138 % end % unless preludes.empty? +#define PRELUDE_STR(n) rb_usascii_str_new_static(prelude_##n.L0, sizeof(prelude_##n)) static void prelude_eval(VALUE code, VALUE name, int line) { @@ -185,8 +189,8 @@ prelude_require(VALUE self, VALUE nth) https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L189 % @preludes.each_value do |i, prelude, lines, sub| % if sub case <%=i%><%=%>: - code = rb_usascii_str_new(prelude_code<%=i%><%=%>.L0, sizeof(prelude_code<%=i%><%=%>)); - name = rb_usascii_str_new(prelude_name<%=i%><%=%>, sizeof(prelude_name<%=i%><%=%>) - 1); + code = PRELUDE_STR(code<%=i%><%=%>); + name = PRELUDE_STR(name<%=i%><%=%>); break; % end % end @@ -218,10 +222,7 @@ Init_<%=@init_name%><%=%>(void) https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L222 % end % preludes.each do |i, prelude, lines, sub| % next if sub - prelude_eval( - rb_usascii_str_new(prelude_code<%=i%><%=%>.L0, sizeof(prelude_code<%=i%><%=%>)), - rb_usascii_str_new(prelude_name<%=i%><%=%>, sizeof(prelude_name<%=i%><%=%>) - 1), - 1); + prelude_eval(PRELUDE_STR(code<%=i%><%=%>), PRELUDE_STR(name<%=i%><%=%>), 1); % end % if @have_sublib rb_gc_force_recycle(prelude); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/