diff options
| author | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-05 00:34:23 +0900 |
|---|---|---|
| committer | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-05 00:34:23 +0900 |
| commit | aa98c575f5f7ae2117f967a6c19f6ba60fe634e4 (patch) | |
| tree | 8a8caf6bb4ed6d0429abc94b27ea8f5bba9307c7 /src | |
| parent | 6be56ef1fbd21b7791e484006ee5b6e342310812 (diff) | |
| download | mruby-aa98c575f5f7ae2117f967a6c19f6ba60fe634e4.tar.gz mruby-aa98c575f5f7ae2117f967a6c19f6ba60fe634e4.zip | |
proper irep pool duplication check for strings
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/codegen.c b/src/codegen.c index 74b6e01f4..6f564586c 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -410,9 +410,27 @@ new_lit(codegen_scope *s, mrb_value val) { int i; - for (i=0; i<s->irep->plen; i++) { - if (mrb_obj_equal(s->mrb, s->irep->pool[i], val)) return i; + + switch (mrb_type(val)) { + case MRB_TT_STRING: + for (i=0; i<s->irep->plen; i++) { + mrb_value pv = s->irep->pool[i]; + mrb_int len; + + if (mrb_type(pv) != MRB_TT_STRING) continue; + if ((len = RSTRING_LEN(pv)) != RSTRING_LEN(val)) continue; + if (memcmp(RSTRING_PTR(pv), RSTRING_PTR(val), len) == 0) + return i; + } + break; + case MRB_TT_FLOAT: + default: + for (i=0; i<s->irep->plen; i++) { + if (mrb_obj_equal(s->mrb, s->irep->pool[i], val)) return i; + } + break; } + if (s->irep->plen == s->pcapa) { s->pcapa *= 2; s->irep->pool = (mrb_value *)codegen_realloc(s, s->irep->pool, sizeof(mrb_value)*s->pcapa); |
