mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Reduce unnecessary symbol table entry
This commit is contained in:
@@ -16,6 +16,7 @@ MRB_BEGIN_DECL
|
||||
|
||||
typedef enum mrb_reserved_symbol {
|
||||
mrb_sym_null = 0, // NULL symbol
|
||||
|
||||
mrb_sym_add = 1, // +
|
||||
mrb_sym_sub = 2, // -
|
||||
mrb_sym_mul = 3, // *
|
||||
@@ -25,9 +26,15 @@ typedef enum mrb_reserved_symbol {
|
||||
mrb_sym_le = 7, // <=
|
||||
mrb_sym_gt = 8, // >
|
||||
mrb_sym_ge = 9, // >=
|
||||
|
||||
mrb_sym_method_missing = 10, // method_missing
|
||||
} mrb_reserved_symbol;
|
||||
|
||||
static inline mrb_bool
|
||||
mrb_symbol_constsym_send_p(mrb_sym sym) {
|
||||
return mrb_sym_add <= sym && sym <= mrb_sym_ge;
|
||||
}
|
||||
|
||||
MRB_END_DECL
|
||||
|
||||
#endif /* MRUBY_SYMBOL_H */
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <mruby/opcode.h>
|
||||
#include <mruby/re.h>
|
||||
#include <mruby/throw.h>
|
||||
#include <mruby/symbol.h>
|
||||
|
||||
#ifndef MRB_CODEGEN_LEVEL_MAX
|
||||
#define MRB_CODEGEN_LEVEL_MAX 1024
|
||||
@@ -982,8 +983,9 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
|
||||
gen_move(s, cursp(), recv, 1);
|
||||
skip = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
|
||||
}
|
||||
// TODO: don't new when unused
|
||||
idx = new_sym(s, sym);
|
||||
if (!mrb_symbol_constsym_send_p(sym)) {
|
||||
idx = new_sym(s, sym);
|
||||
}
|
||||
tree = tree->cdr->cdr->car;
|
||||
if (tree) {
|
||||
n = gen_values(s, tree->car, VAL, sp?1:0);
|
||||
@@ -2024,7 +2026,9 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
push(); pop();
|
||||
pop(); pop();
|
||||
|
||||
idx = new_sym(s, sym);
|
||||
if (!mrb_symbol_constsym_send_p(sym)) {
|
||||
idx = new_sym(s, sym);
|
||||
}
|
||||
if (len == 1 && name[0] == '+') {
|
||||
gen_addsub(s, OP_ADD, cursp());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user