From bdcf8a4bcb23014d8e5e4f3bac3f778761fd84ae Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 22 Mar 2014 19:03:20 +0900 Subject: [PATCH] change ugly implementation; don't call realloc for each puching! --- src/codegen.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/codegen.c b/src/codegen.c index 69746458..09ae52ee 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1109,12 +1109,10 @@ create_cv_table(pic_state *pic, codegen_context *cxt) } /* closed variables */ - cxt->cv_tbl = NULL; - cxt->cv_num = 0; + cxt->cv_num = cxt->captures.size; + cxt->cv_tbl = pic_calloc(pic, cxt->cv_num, sizeof(unsigned)); for (i = 0; i < cxt->captures.size; ++i) { var = xv_get(&cxt->captures, i); - i = cxt->cv_num++; - cxt->cv_tbl = pic_realloc(pic, cxt->cv_tbl, sizeof(unsigned) * cxt->cv_num); cxt->cv_tbl[i] = xh_get_int(vars, *var)->val; }