zero copy intern from static allocate irep

parent c6ceed22
......@@ -38,7 +38,7 @@ offset_crc_body(void)
}
static mrb_irep*
read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len, mrb_bool alloc)
{
size_t i;
const uint8_t *src = bin;
......@@ -144,7 +144,12 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
continue;
}
irep->syms[i] = mrb_intern(mrb, (char *)src, snl);
if (alloc) {
irep->syms[i] = mrb_intern(mrb, (char *)src, snl);
}
else {
irep->syms[i] = mrb_intern_static(mrb, (char *)src, snl);
}
src += snl + 1;
mrb_gc_arena_restore(mrb, ai);
......@@ -158,16 +163,16 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
}
static mrb_irep*
read_irep_record(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
read_irep_record(mrb_state *mrb, const uint8_t *bin, uint32_t *len, mrb_bool alloc)
{
mrb_irep *irep = read_irep_record_1(mrb, bin, len);
mrb_irep *irep = read_irep_record_1(mrb, bin, len, alloc);
size_t i;
bin += *len;
for (i=0; i<irep->rlen; i++) {
uint32_t rlen;
irep->reps[i] = read_irep_record(mrb, bin, &rlen);
irep->reps[i] = read_irep_record(mrb, bin, &rlen, alloc);
bin += rlen;
*len += rlen;
}
......@@ -175,12 +180,12 @@ read_irep_record(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
}
static mrb_irep*
read_section_irep(mrb_state *mrb, const uint8_t *bin)
read_section_irep(mrb_state *mrb, const uint8_t *bin, mrb_bool alloc)
{
uint32_t len;
bin += sizeof(struct rite_section_irep_header);
return read_irep_record(mrb, bin, &len);
return read_irep_record(mrb, bin, &len, alloc);
}
static int
......@@ -430,7 +435,7 @@ mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
do {
section_header = (const struct rite_section_header *)bin;
if (memcmp(section_header->section_identify, RITE_SECTION_IREP_IDENTIFIER, sizeof(section_header->section_identify)) == 0) {
irep = read_section_irep(mrb, bin);
irep = read_section_irep(mrb, bin, FALSE);
if (!irep) return NULL;
}
else if (memcmp(section_header->section_identify, RITE_SECTION_LINENO_IDENTIFIER, sizeof(section_header->section_identify)) == 0) {
......@@ -561,7 +566,7 @@ read_irep_record_file(mrb_state *mrb, FILE *fp)
if (fread(&buf[record_header_size], buf_size - record_header_size, 1, fp) == 0) {
return NULL;
}
irep = read_irep_record_1(mrb, buf, &len);
irep = read_irep_record_1(mrb, buf, &len, TRUE);
mrb_free(mrb, ptr);
if (!irep) return NULL;
for (i=0; i<irep->rlen; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment