* parse.y (list_append): avoid O(n) search using node->nd_next->nd_end.

* parse.y (list_append): ditto.

* eval.c (rb_eval): NODE_ARRY nd_end adoption.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-01-14 07:45:19 +00:00
parent 8c900ac9bf
commit 6e1f15fc8b
5 changed files with 76 additions and 34 deletions

View File

@ -2,6 +2,14 @@ Tue Jan 14 01:21:32 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* io.c (next_argv): not always set binmode. * io.c (next_argv): not always set binmode.
Mon Jan 13 20:45:19 2003 Guy Decoux <ts@moulon.inra.fr>
* parse.y (list_append): avoid O(n) search using node->nd_next->nd_end.
* parse.y (list_append): ditto.
* eval.c (rb_eval): NODE_ARRY nd_end adoption.
Mon Jan 13 02:22:11 2003 WATANABE Hirofumi <eban@ruby-lang.org> Mon Jan 13 02:22:11 2003 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/dl/lib/dl/win32.rb: elimitate unnecessary "A" adding. * ext/dl/lib/dl/win32.rb: elimitate unnecessary "A" adding.

View File

@ -31,6 +31,7 @@ VALUE rb_cBignum;
#define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG) #define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG)
#define BIGDN(x) RSHIFT(x,BITSPERDIG) #define BIGDN(x) RSHIFT(x,BITSPERDIG)
#define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1))) #define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
#define BDIGMAX ((BDIGIT)-1)
static VALUE static VALUE
bignew_1(klass, len, sign) bignew_1(klass, len, sign)

63
eval.c
View File

@ -186,12 +186,14 @@ struct cache_entry { /* method hash table. */
}; };
static struct cache_entry cache[CACHE_SIZE]; static struct cache_entry cache[CACHE_SIZE];
static int ruby_running = 0;
void void
rb_clear_cache() rb_clear_cache()
{ {
struct cache_entry *ent, *end; struct cache_entry *ent, *end;
if (!ruby_running) return;
ent = cache; end = ent + CACHE_SIZE; ent = cache; end = ent + CACHE_SIZE;
while (ent < end) { while (ent < end) {
ent->mid = 0; ent->mid = 0;
@ -205,6 +207,7 @@ rb_clear_cache_by_id(id)
{ {
struct cache_entry *ent, *end; struct cache_entry *ent, *end;
if (!ruby_running) return;
ent = cache; end = ent + CACHE_SIZE; ent = cache; end = ent + CACHE_SIZE;
while (ent < end) { while (ent < end) {
if (ent->mid == id) { if (ent->mid == id) {
@ -220,6 +223,7 @@ rb_clear_cache_by_class(klass)
{ {
struct cache_entry *ent, *end; struct cache_entry *ent, *end;
if (!ruby_running) return;
ent = cache; end = ent + CACHE_SIZE; ent = cache; end = ent + CACHE_SIZE;
while (ent < end) { while (ent < end) {
if (ent->origin == klass) { if (ent->origin == klass) {
@ -322,26 +326,40 @@ rb_get_method_body(klassp, idp, noexp)
return 0; return 0;
} }
/* store in cache */ if (ruby_running) {
ent = cache + EXPR1(klass, id); /* store in cache */
ent->klass = klass; ent = cache + EXPR1(klass, id);
ent->noex = body->nd_noex; ent->klass = klass;
body = body->nd_body; ent->noex = body->nd_noex;
if (nd_type(body) == NODE_FBODY) { if (noexp) *noexp = body->nd_noex;
ent->mid = id; body = body->nd_body;
*klassp = body->nd_orig; if (nd_type(body) == NODE_FBODY) {
ent->origin = body->nd_orig; ent->mid = id;
*idp = ent->mid0 = body->nd_mid; *klassp = body->nd_orig;
body = ent->method = body->nd_head; ent->origin = body->nd_orig;
*idp = ent->mid0 = body->nd_mid;
body = ent->method = body->nd_head;
}
else {
*klassp = origin;
ent->origin = origin;
ent->mid = ent->mid0 = id;
ent->method = body;
}
} }
else { else {
*klassp = origin; if (noexp) *noexp = body->nd_noex;
ent->origin = origin; body = body->nd_body;
ent->mid = ent->mid0 = id; if (nd_type(body) == NODE_FBODY) {
ent->method = body; *klassp = body->nd_orig;
*idp = body->nd_mid;
body = body->nd_head;
}
else {
*klassp = origin;
}
} }
if (noexp) *noexp = ent->noex;
return body; return body;
} }
@ -1287,6 +1305,7 @@ ruby_exec()
volatile NODE *tmp; volatile NODE *tmp;
Init_stack((void*)&tmp); Init_stack((void*)&tmp);
ruby_running = 1;
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
PUSH_ITER(ITER_NOT); PUSH_ITER(ITER_NOT);
/* default visibility is private at toplevel */ /* default visibility is private at toplevel */
@ -1311,6 +1330,7 @@ ruby_run()
{ {
int state; int state;
static int ex; static int ex;
if (ruby_nerrs > 0) exit(ruby_nerrs); if (ruby_nerrs > 0) exit(ruby_nerrs);
state = ruby_exec(); state = ruby_exec();
if (state && !ex) ex = state; if (state && !ex) ex = state;
@ -1796,14 +1816,14 @@ copy_node_scope(node, rval)
# define TMP_ALLOC(n) ALLOCA_N(VALUE,n) # define TMP_ALLOC(n) ALLOCA_N(VALUE,n)
#endif #endif
#define SETUP_ARGS(anode) do {\ #define SETUP_ARGS0(anode,alen) do {\
NODE *n = anode;\ NODE *n = anode;\
if (!n) {\ if (!n) {\
argc = 0;\ argc = 0;\
argv = 0;\ argv = 0;\
}\ }\
else if (nd_type(n) == NODE_ARRAY) {\ else if (nd_type(n) == NODE_ARRAY) {\
argc=n->nd_alen;\ argc=alen;\
if (argc > 0) {\ if (argc > 0) {\
int i;\ int i;\
n = anode;\ n = anode;\
@ -1828,6 +1848,8 @@ copy_node_scope(node, rval)
}\ }\
} while (0) } while (0)
#define SETUP_ARGS(anode) SETUP_ARGS0(anode, anode->nd_alen)
#define BEGIN_CALLARGS do {\ #define BEGIN_CALLARGS do {\
struct BLOCK *tmp_block = ruby_block;\ struct BLOCK *tmp_block = ruby_block;\
if (ruby_iter->iter == ITER_PRE) {\ if (ruby_iter->iter == ITER_PRE) {\
@ -2854,7 +2876,7 @@ rb_eval(self, n)
recv = rb_eval(self, node->nd_recv); recv = rb_eval(self, node->nd_recv);
rval = node->nd_args->nd_head; rval = node->nd_args->nd_head;
SETUP_ARGS(node->nd_args->nd_next); SETUP_ARGS0(node->nd_args->nd_next, node->nd_args->nd_alen - 1);
val = rb_funcall2(recv, aref, argc-1, argv); val = rb_funcall2(recv, aref, argc-1, argv);
switch (node->nd_mid) { switch (node->nd_mid) {
case 0: /* OR */ case 0: /* OR */
@ -9578,6 +9600,9 @@ rb_f_throw(argc, argv)
return_value(value); return_value(value);
rb_trap_restore_mask(); rb_trap_restore_mask();
JUMP_TAG(TAG_THROW); JUMP_TAG(TAG_THROW);
#ifndef __GNUC__
return Qnil; /* not reached */
#endif
} }
void void

6
pack.c
View File

@ -57,10 +57,10 @@ TOKEN_PASTE(swap,x)(z) \
unsigned char *s, *t; \ unsigned char *s, *t; \
int i; \ int i; \
\ \
zp = (xtype *)malloc(sizeof(xtype));\ zp = malloc(sizeof(xtype)); \
*zp = z; \ *zp = z; \
s = (char *)zp; \ s = (unsigned char*)zp; \
t = (char *)malloc(sizeof(xtype)); \ t = malloc(sizeof(xtype)); \
for (i=0; i<sizeof(xtype); i++) { \ for (i=0; i<sizeof(xtype); i++) { \
t[sizeof(xtype)-i-1] = s[i]; \ t[sizeof(xtype)-i-1] = s[i]; \
} \ } \

32
parse.y
View File

@ -4501,14 +4501,16 @@ list_append(list, item)
NODE *last; NODE *last;
if (list == 0) return NEW_LIST(item); if (list == 0) return NEW_LIST(item);
if (list->nd_next) {
last = list; last = list->nd_next->nd_end;
while (last->nd_next) { }
last = last->nd_next; else {
last = list;
} }
last->nd_next = NEW_LIST(item);
list->nd_alen += 1; list->nd_alen += 1;
last->nd_next = NEW_LIST(item);
list->nd_next->nd_end = last->nd_next;
return list; return list;
} }
@ -4519,13 +4521,21 @@ list_concat(head, tail)
{ {
NODE *last; NODE *last;
last = head; if (head->nd_next) {
while (last->nd_next) { last = head->nd_next->nd_end;
last = last->nd_next; }
else {
last = head;
} }
last->nd_next = tail;
head->nd_alen += tail->nd_alen; head->nd_alen += tail->nd_alen;
last->nd_next = tail;
if (tail->nd_next) {
head->nd_next->nd_end = tail->nd_next->nd_end;
}
else {
head->nd_next->nd_end = tail;
}
return head; return head;
} }
@ -4543,9 +4553,7 @@ literal_concat(head, tail)
htype = nd_type(head); htype = nd_type(head);
if (htype == NODE_EVSTR) { if (htype == NODE_EVSTR) {
NODE *node = NEW_DSTR(rb_str_new(0, 0)); NODE *node = NEW_DSTR(rb_str_new(0, 0));
node->nd_next = NEW_LIST(head); head = list_append(node, head);
node->nd_alen += 1;
head = node;
} }
switch (nd_type(tail)) { switch (nd_type(tail)) {
case NODE_STR: case NODE_STR: