1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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

6
pack.c
View file

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

32
parse.y
View file

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