1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

prelude.c.tmpl: static literals

* template/prelude.c.tmpl (PRELUDE_STR): make string objects with
  static literals not to copy them.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-12-25 02:42:13 +00:00
parent d9c76c5bd8
commit d66f2d4443

View file

@ -85,7 +85,10 @@ Prelude.new(output && output[/\w+(?=_prelude.c\b)/] || 'prelude', ARGV, vpath).i
% 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)
% 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)
% @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)
% 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);