summaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-25 02:42:13 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-25 02:42:13 (GMT)
commitd66f2d44434de14899bc20b053238ea833360ec2 (patch)
tree157b4e03ac7da781a70c6cbc49aa240bb3f2922f /template
parentd9c76c5bd8c60f488d3decbcd5c2b46108bdba6e (diff)
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
Diffstat (limited to 'template')
-rw-r--r--template/prelude.c.tmpl15
1 files changed, 8 insertions, 7 deletions
diff --git a/template/prelude.c.tmpl b/template/prelude.c.tmpl
index f755a39..72c8c71 100644
--- a/template/prelude.c.tmpl
+++ b/template/prelude.c.tmpl
@@ -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);