summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-12 01:15:17 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-12 01:15:17 +0000
commit1acc981a539813e6ec2a5c50f3d91f946a4da1a6 (patch)
treec7e7434c001d81701f583a30b5e10c51390e51e2
parent600d59db733b266a706bf74c4f2083cf7940e471 (diff)
speed up patch 4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--eval.c3
-rw-r--r--io.c16
-rw-r--r--parse.y99
3 files changed, 33 insertions, 85 deletions
diff --git a/eval.c b/eval.c
index 47b23e9f66..4c070729e7 100644
--- a/eval.c
+++ b/eval.c
@@ -3354,7 +3354,8 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
if (local_vars) {
if (i > 0) {
- MEMCPY(local_vars, argv, VALUE, i);
+ /* +2 for $_ and $~ */
+ MEMCPY(local_vars+2, argv, VALUE, i);
}
argv += i; argc -= i;
if (node->nd_opt) {
diff --git a/io.c b/io.c
index a52cea488b..751a5ef393 100644
--- a/io.c
+++ b/io.c
@@ -442,11 +442,9 @@ io_gets_method(argc, argv, io)
c = cnt ? 0 : EOF;
}
- if (c == EOF) {
- if (!append && cnt == 0) {
- str = Qnil;
- goto return_gets;
- }
+ if (c == EOF && !append && cnt == 0) {
+ str = Qnil;
+ goto return_gets;
}
if (append)
@@ -517,11 +515,9 @@ io_gets(io)
}
cnt = bp - buf;
- if (c == EOF) {
- if (!append && cnt == 0) {
- str = Qnil;
- goto return_gets;
- }
+ if (c == EOF && !append && cnt == 0) {
+ str = Qnil;
+ goto return_gets;
}
if (append)
diff --git a/parse.y b/parse.y
index e82fdfc553..1c63a28df7 100644
--- a/parse.y
+++ b/parse.y
@@ -3648,15 +3648,6 @@ logop(type, left, right)
NODE *left, *right;
{
value_expr(left);
-
- switch (nd_type(left)) {
- case NODE_NIL: /* always false */
- case NODE_FALSE:
- return type == NODE_OR ? right : left;
- case NODE_LIT: /* always true */
- return type == NODE_AND ? right : left;
- }
-
return node_newnode(type, cond(left), cond(right));
}
@@ -3728,13 +3719,7 @@ local_pop()
if (lvtbl->tbl) {
if (!lvtbl->nofree) free(lvtbl->tbl);
- else {
- lvtbl->tbl[0] = lvtbl->cnt;
-#if 1
- lvtbl->tbl[lvtbl->cnt+1] = local_cnt('_');
- lvtbl->tbl[lvtbl->cnt+2] = local_cnt('~');
-#endif
- }
+ else lvtbl->tbl[0] = lvtbl->cnt;
}
free(lvtbl);
lvtbl = local;
@@ -3743,10 +3728,6 @@ local_pop()
static ID*
local_tbl()
{
-#if 1
- local_cnt('_');
- local_cnt('~');
-#endif
lvtbl->nofree = 1;
return lvtbl->tbl;
}
@@ -3764,11 +3745,16 @@ local_cnt(id)
}
if (lvtbl->tbl == 0) {
- lvtbl->tbl = ALLOC_N(ID, 2);
+ lvtbl->tbl = ALLOC_N(ID, 4);
lvtbl->tbl[0] = 0;
+ lvtbl->tbl[1] = '_';
+ lvtbl->tbl[2] = '~';
+ lvtbl->cnt = 2;
+ if (id == '_') return 0;
+ if (id == '~') return 1;
}
else {
- REALLOC_N(lvtbl->tbl, ID, lvtbl->cnt+4);
+ REALLOC_N(lvtbl->tbl, ID, lvtbl->cnt+2);
}
lvtbl->tbl[lvtbl->cnt+1] = id;
@@ -4109,38 +4095,13 @@ local_var_append(id)
lvtbl = save;
}
-static VALUE
-special_local_get(c)
- char c;
-{
- int cnt, max;
-
- if (!the_scope->local_vars) return Qnil;
- for (cnt=1, max=the_scope->local_tbl[0]+1; cnt<max ;cnt++) {
- if (the_scope->local_tbl[cnt] == c) {
- return the_scope->local_vars[cnt-1];
- }
- }
- return Qnil;
-}
-
static void
special_local_set(c, val)
char c;
VALUE val;
{
- int cnt, max;
+ int cnt;
-#if 0
- if (the_scope->local_tbl) {
- for (cnt=1, max=the_scope->local_tbl[0]+1; cnt<max ;cnt++) {
- if (the_scope->local_tbl[cnt] == c) {
- the_scope->local_vars[cnt-1] = val;
- return;
- }
- }
- }
-#endif
top_local_init();
cnt = local_cnt(c);
top_local_setup();
@@ -4150,51 +4111,41 @@ special_local_set(c, val)
VALUE
backref_get()
{
-#if 1
- if (the_scope->local_tbl) {
- return the_scope->local_vars[the_scope->local_tbl[the_scope->local_tbl[0]+2]];
+ if (the_scope->local_vars) {
+ return the_scope->local_vars[1];
}
return Qnil;
-#else
- return special_local_get('~');
-#endif
}
void
backref_set(val)
VALUE val;
{
-#if 1
- if (the_scope->local_tbl) {
- the_scope->local_vars[the_scope->local_tbl[the_scope->local_tbl[0]+2]] = val;
- } else
-#endif
- special_local_set('~', val);
+ if (the_scope->local_vars) {
+ the_scope->local_vars[1] = val;
+ }
+ else {
+ special_local_set('~', val);
+ }
}
VALUE
lastline_get()
{
-#if 1
- if (the_scope->local_tbl) {
- return the_scope->local_vars[the_scope->local_tbl[the_scope->local_tbl[0]+1]];
+ if (the_scope->local_vars) {
+ return the_scope->local_vars[0];
}
return Qnil;
-#else
- VALUE v = special_local_get('_');
- if (v == 1) return Qnil; /* $_ undefined */
- return v;
-#endif
}
void
lastline_set(val)
VALUE val;
{
-#if 1
- if (the_scope->local_tbl) {
- the_scope->local_vars[the_scope->local_tbl[the_scope->local_tbl[0]+1]] = val;
- } else
-#endif
- special_local_set('_', val);
+ if (the_scope->local_vars) {
+ the_scope->local_vars[0] = val;
+ }
+ else {
+ special_local_set('_', val);
+ }
}