summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-24 08:36:53 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-24 08:36:53 +0000
commit2314b80d4c5ed712308f6b32aa8bf865d8d9ffff (patch)
tree8a531352ebd8b352e6c1b5cadeeb7d49d28da147 /iseq.c
parent8ac52a95d577d00ed7b783fde8bca5b2b76cb404 (diff)
Feature #7035
* compile.c (defined_expr), insns.def (defined): share single frozen strings. [EXPERIMENTAL] [ruby-core:47558][Feature #7035] * iseq.c (rb_iseq_defined_string): make expression strings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/iseq.c b/iseq.c
index 8d8d92174d..989a8a1120 100644
--- a/iseq.c
+++ b/iseq.c
@@ -18,6 +18,8 @@
#include "vm_core.h"
#include "iseq.h"
+#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
+
#include "insns.inc"
#include "insns_info.inc"
@@ -1747,6 +1749,45 @@ rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
return args;
}
+VALUE
+rb_iseq_defined_string(enum defined_type type)
+{
+ static const char expr_names[][18] = {
+ "nil",
+ "instance-variable",
+ "local-variable",
+ "global-variable",
+ "class variable",
+ "constant",
+ "method",
+ "yield",
+ "super",
+ "self",
+ "true",
+ "false",
+ "assignment",
+ "expression",
+ };
+ const char *estr;
+ VALUE *defs, str;
+
+ if ((unsigned)(type - 1) >= (unsigned)numberof(expr_names)) return 0;
+ estr = expr_names[type - 1];
+ if (!estr[0]) return 0;
+ defs = GET_VM()->defined_strings;
+ if (!defs) {
+ defs = ruby_xcalloc(numberof(expr_names), sizeof(VALUE));
+ GET_VM()->defined_strings = defs;
+ }
+ str = defs[type];
+ if (!str) {
+ str = rb_str_new_cstr(estr);;
+ OBJ_FREEZE(str);
+ defs[type] = str;
+ }
+ return str;
+}
+
/* ruby2cext */
VALUE