diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | ToDo | 1 | ||||
-rw-r--r-- | class.c | 3 | ||||
-rw-r--r-- | eval.c | 5 | ||||
-rw-r--r-- | hash.c | 16 | ||||
-rw-r--r-- | lib/mailread.rb | 22 | ||||
-rw-r--r-- | lib/open3.rb | 9 | ||||
-rw-r--r-- | st.c | 72 | ||||
-rw-r--r-- | string.c | 39 | ||||
-rw-r--r-- | version.h | 4 |
10 files changed, 107 insertions, 73 deletions
@@ -1,3 +1,12 @@ +Fri Feb 25 12:50:20 2000 Yukihiro Matsumoto <matz@netlab.co.jp> + + * eval.c (rb_thread_start_timer): interval made 10ms from 50ms. + +Thu Feb 24 16:53:47 2000 Yukihiro Matsumoto <matz@netlab.co.jp> + + * eval.c (rb_thread_schedule): priority check for sleep expired + threads needed. + Wed Feb 23 14:22:32 2000 Yukihiro Matsumoto <matz@netlab.co.jp> * array.c (rb_ary_join): forgot to initialize a local variable @@ -66,6 +66,7 @@ Standard Libraries * String#{pred,prev}, String#downto * optional stepsize argument for succ() * performance tune for String's non-bang methods. +* Ruby module -- Ruby::Version, Ruby::Interpreter Extension Libraries @@ -605,6 +605,8 @@ rb_scan_args(argc, argv, fmt, va_alist) va_init_list(vargs, fmt); + if (*p == '*') goto rest_arg; + if (ISDIGIT(*p)) { n = *p - '0'; if (n > argc) @@ -634,6 +636,7 @@ rb_scan_args(argc, argv, fmt, va_alist) } if(*p == '*') { + rest_arg: var = va_arg(vargs, VALUE*); if (argc > i) { if (var) *var = rb_ary_new4(argc-i, argv+i); @@ -6603,7 +6603,8 @@ rb_thread_schedule() th->wait_for &= ~WAIT_TIME; th->status = THREAD_RUNNABLE; num_waiting_on_timer--; - next = th; + if (!next || next->priority < th->priority) + next = th; } else if (th->delay < delay) { delay = th->delay; } @@ -7216,7 +7217,7 @@ rb_thread_start_timer() if (!thread_init) return; tval.it_interval.tv_sec = 0; - tval.it_interval.tv_usec = 50000; + tval.it_interval.tv_usec = 10000; tval.it_value = tval.it_interval; setitimer(ITIMER_VIRTUAL, &tval, NULL); } @@ -89,23 +89,7 @@ rb_any_hash(a) break; case T_STRING: -#if 0 hval = rb_str_hash(a); -#else - { - register const char *p = RSTRING(a)->ptr; - register int len = RSTRING(a)->len; - register unsigned int h = 0, g; - - while (len--) { - h = ( h << 4 ) + *p++; - if ( g = h & 0xF0000000 ) - h ^= g >> 24; - h &= ~g; - } - hval = h; - } -#endif break; default: diff --git a/lib/mailread.rb b/lib/mailread.rb index 2edcca002a..ee86d353eb 100644 --- a/lib/mailread.rb +++ b/lib/mailread.rb @@ -9,25 +9,25 @@ class Mail @header = {} @body = [] begin - while f.gets() - $_.chop! - next if /^From / # skip From-line - break if /^$/ # end of header + while line = f.gets() + line.chop! + next if /^From /=~line # skip From-line + break if /^$/=~line # end of header - if /^(\S+):\s*(.*)/ + if /^(\S+):\s*(.*)/=~line (attr = $1).capitalize! @header[attr] = $2 elsif attr - sub!(/^\s*/, '') - @header[attr] += "\n" + $_ + line.sub!(/^\s*/, '') + @header[attr] += "\n" + line end end - return unless $_ + return unless line - while f.gets() - break if /^From / - @body.push($_) + while line = f.gets() + break if /^From /=~line + @body.push(line) end ensure f.close if opened diff --git a/lib/open3.rb b/lib/open3.rb index 9e34acffc9..27283f5019 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -43,13 +43,12 @@ end if $0 == __FILE__ a = Open3.popen3("nroff -man") Thread.start do - while gets - a[0].print $_ + while line = gets + a[0].print line end a[0].close end - while a[1].gets - print ":", $_ + while line = a[1].gets + print ":", line end end - @@ -62,7 +62,7 @@ static void rehash(); #define EQUAL(table, x, y) ((*table->type->compare)(x, y) == 0) #define do_hash(key, table) (unsigned int)(*(table)->type->hash)((key)) -#define do_hash_bin(key, table) (do_hash(key, table)%(table)->num_bins) +#define do_hash_bin(key, table) (do_hash(key, table)&(table)->num_bins) /* * MINSIZE is the minimum size of a dictionary. @@ -112,6 +112,11 @@ new_size(size) int i, newsize; #if 1 + for (i=3; i<31; i++) { + if ((1<<i) > size) return 1<<i; + } + return -1; +#else for (i = 0, newsize = MINSIZE; i < sizeof(primes)/sizeof(primes[0]); i++, newsize <<= 1) @@ -120,14 +125,10 @@ new_size(size) } /* Ran out of polynomials */ return -1; /* should raise exception */ -#else - for (i=3; i<31; i++) { - if ((1<<i) > size) return 1<<i; - } - return -1; #endif } +#ifdef HASH_LOG static int collision = 0; static int init_st = 0; @@ -138,6 +139,7 @@ stat_col() fprintf(f, "collision: %d\n", collision); fclose(f); } +#endif st_table* st_init_table_with_size(type, size) @@ -146,7 +148,7 @@ st_init_table_with_size(type, size) { st_table *tbl; -#if 0 +#ifdef HASH_LOG if (init_st == 0) { init_st = 1; atexit(stat_col); @@ -158,7 +160,7 @@ st_init_table_with_size(type, size) tbl = alloc(st_table); tbl->type = type; tbl->num_entries = 0; - tbl->num_bins = size; + tbl->num_bins = size-1; tbl->bins = (st_table_entry **)Calloc(size, sizeof(st_table_entry*)); return tbl; @@ -204,7 +206,7 @@ st_free_table(table) register st_table_entry *ptr, *next; int i; - for(i = 0; i < table->num_bins; i++) { + for(i = 0; i <= table->num_bins; i++) { ptr = table->bins[i]; while (ptr != 0) { next = ptr->next; @@ -219,11 +221,17 @@ st_free_table(table) #define PTR_NOT_EQUAL(table, ptr, hash_val, key) \ ((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key))) +#ifdef HASH_LOG +#define COLLISION collision++ +#else +#define COLLISION +#endif + #define FIND_ENTRY(table, ptr, hash_val, bin_pos) \ -bin_pos = hash_val%(table)->num_bins;\ +bin_pos = hash_val&(table)->num_bins;\ ptr = (table)->bins[bin_pos];\ if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\ - collision++;\ + COLLISION;\ while (PTR_NOT_EQUAL(table, ptr->next, hash_val, key)) {\ ptr = ptr->next;\ }\ @@ -253,9 +261,9 @@ st_lookup(table, key, value) #define ADD_DIRECT(table, key, value, hash_val, bin_pos)\ {\ st_table_entry *entry;\ - if (table->num_entries/table->num_bins > ST_DEFAULT_MAX_DENSITY) {\ + if (table->num_entries/(table->num_bins+1) > ST_DEFAULT_MAX_DENSITY) {\ rehash(table);\ - bin_pos = hash_val % table->num_bins;\ + bin_pos = hash_val & table->num_bins;\ }\ \ entry = alloc(st_table_entry);\ @@ -298,7 +306,7 @@ st_add_direct(table, key, value) unsigned int hash_val, bin_pos; hash_val = do_hash(key, table); - bin_pos = hash_val % table->num_bins; + bin_pos = hash_val & table->num_bins; ADD_DIRECT(table, key, value, hash_val, bin_pos); } @@ -310,14 +318,15 @@ rehash(table) int i, old_num_bins = table->num_bins, new_num_bins; unsigned int hash_val; - new_num_bins = new_size(old_num_bins); + new_num_bins = new_size(old_num_bins+1); new_bins = (st_table_entry**)Calloc(new_num_bins, sizeof(st_table_entry*)); - for(i = 0; i < old_num_bins; i++) { + new_num_bins--; + for(i = 0; i <= old_num_bins; i++) { ptr = table->bins[i]; while (ptr != 0) { next = ptr->next; - hash_val = ptr->hash % new_num_bins; + hash_val = ptr->hash & new_num_bins; ptr->next = new_bins[hash_val]; new_bins[hash_val] = ptr; ptr = next; @@ -334,7 +343,7 @@ st_copy(old_table) { st_table *new_table; st_table_entry *ptr, *entry; - int i, num_bins = old_table->num_bins; + int i, num_bins = old_table->num_bins+1; new_table = alloc(st_table); if (new_table == 0) { @@ -471,7 +480,7 @@ st_foreach(table, func, arg) enum st_retval retval; int i; - for(i = 0; i < table->num_bins; i++) { + for(i = 0; i <= table->num_bins; i++) { last = 0; for(ptr = table->bins[i]; ptr != 0;) { retval = (*func)(ptr->key, ptr->record, arg); @@ -501,14 +510,35 @@ static int strhash(string) register char *string; { - register int val = 0; register int c; +#ifdef HASH_ELFHASH + register unsigned int h = 0, g; + + while ((c = *string++) != '\0') { + h = ( h << 4 ) + c; + if ( g = h & 0xF0000000 ) + h ^= g >> 24; + h &= ~g; + } + return h; +#elif HASH_PERL + register int val = 0; + + while ((c = *string++) != '\0') { + val = val*33 + c; + } + + return val + (val>>5); +#else + register int val = 0; + while ((c = *string++) != '\0') { val = val*997 + c; } - return val; + return val + (val>>5); +#endif } static int @@ -421,29 +421,39 @@ rb_str_hash(str) register char *p = RSTRING(str)->ptr; register int key = 0; -#if 0 +#ifdef HASH_ELFHASH + register unsigned int g; + + while (len--) { + key = (key << 4) + *p++; + if (g = key & 0xF0000000) + key ^= g >> 24; + key &= ~g; + } +#elif HASH_PERL if (ruby_ignorecase) { while (len--) { - key = key*65599 + toupper(*p); + key = key*33 + toupper(*p); p++; } } else { while (len--) { - key = key*65599 + *p; - p++; + key = key*33 + *p++; } } + key = key + (key>>5); #else if (ruby_ignorecase) { while (len--) { - key = key*33 + toupper(*p); + key = key*65599 + toupper(*p); p++; } } else { while (len--) { - key = key*33 + *p++; + key = key*65599 + *p; + p++; } } key = key + (key>>5); @@ -943,16 +953,13 @@ rb_str_aset_m(argc, argv, str) VALUE *argv; VALUE str; { - VALUE arg1, arg2, arg3; - rb_str_modify(str); - - if (rb_scan_args(argc, argv, "21", &arg1, &arg2, &arg3) == 3) { + if (argc == 3) { int beg, len; - if (TYPE(arg3) != T_STRING) arg3 = rb_str_to_str(arg3); - beg = NUM2INT(arg1); - len = NUM2INT(arg2); + if (TYPE(argv[2]) != T_STRING) argv[2] = rb_str_to_str(argv[2]); + beg = NUM2INT(argv[0]); + len = NUM2INT(argv[1]); if (len < 0) rb_raise(rb_eIndexError, "negative length %d", len); if (beg < 0) { beg += RSTRING(str)->len; @@ -966,10 +973,10 @@ rb_str_aset_m(argc, argv, str) if (beg + len > RSTRING(str)->len) { len = RSTRING(str)->len - beg; } - rb_str_replace(str, beg, len, arg3); - return arg3; + rb_str_replace(str, beg, len, argv[2]); + return argv[2]; } - return rb_str_aset(str, arg1, arg2); + return rb_str_aset(str, argv[0], argv[1]); } static VALUE @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.5.2" -#define RUBY_RELEASE_DATE "2000-02-23" +#define RUBY_RELEASE_DATE "2000-02-25" #define RUBY_VERSION_CODE 152 -#define RUBY_RELEASE_CODE 20000223 +#define RUBY_RELEASE_CODE 20000225 |