avoid unnecessary copy of context->filename

This commit is contained in:
Yukihiro "Matz" Matsumoto
2013-05-15 00:08:28 +09:00
parent 95fb1fd809
commit 103ab2e53d
+5 -3
View File
@@ -158,18 +158,20 @@ partial_hook(struct mrb_parser_state *p)
{
mrbc_context *c = p->cxt;
struct mrbc_args *args = (struct mrbc_args *)c->partial_data;
const char *fn;
if (p->f) fclose(p->f);
if (args->idx >= args->argc) {
p->f = NULL;
return -1;
}
mrbc_filename(p->mrb, c, args->argv[args->idx++]);
p->f = fopen(c->filename, "r");
fn = args->argv[args->idx++];
p->f = fopen(fn, "r");
if (p->f == NULL) {
fprintf(stderr, "%s: cannot open program file. (%s)\n", args->prog, c->filename);
fprintf(stderr, "%s: cannot open program file. (%s)\n", args->prog, fn);
return -1;
}
mrbc_filename(p->mrb, c, fn);
p->filename = c->filename;
p->lineno = 1;
return 0;