Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

2000-02-25

git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit a4fce2fabf06a1b1f9438148376b35e3dffd3eb5 1 parent 4d76d71
authored
9  ChangeLog
... ...
@@ -1,3 +1,12 @@
  1
+Fri Feb 25 12:50:20 2000  Yukihiro Matsumoto  <matz@netlab.co.jp>
  2
+
  3
+	* eval.c (rb_thread_start_timer): interval made 10ms from 50ms.
  4
+
  5
+Thu Feb 24 16:53:47 2000  Yukihiro Matsumoto  <matz@netlab.co.jp>
  6
+
  7
+	* eval.c (rb_thread_schedule): priority check for sleep expired
  8
+	  threads needed.
  9
+
1 10
 Wed Feb 23 14:22:32 2000  Yukihiro Matsumoto  <matz@netlab.co.jp>
2 11
 
3 12
 	* array.c (rb_ary_join): forgot to initialize a local variable
1  ToDo
@@ -66,6 +66,7 @@ Standard Libraries
66 66
 * String#{pred,prev}, String#downto
67 67
 * optional stepsize argument for succ()
68 68
 * performance tune for String's non-bang methods.
  69
+* Ruby module -- Ruby::Version, Ruby::Interpreter
69 70
 
70 71
 Extension Libraries
71 72
 
3  class.c
@@ -605,6 +605,8 @@ rb_scan_args(argc, argv, fmt, va_alist)
605 605
 
606 606
     va_init_list(vargs, fmt);
607 607
 
  608
+    if (*p == '*') goto rest_arg;
  609
+
608 610
     if (ISDIGIT(*p)) {
609 611
 	n = *p - '0';
610 612
 	if (n > argc)
@@ -634,6 +636,7 @@ rb_scan_args(argc, argv, fmt, va_alist)
634 636
     }
635 637
 
636 638
     if(*p == '*') {
  639
+      rest_arg:
637 640
 	var = va_arg(vargs, VALUE*);
638 641
 	if (argc > i) {
639 642
 	    if (var) *var = rb_ary_new4(argc-i, argv+i);
5  eval.c
@@ -6603,7 +6603,8 @@ rb_thread_schedule()
6603 6603
 			    th->wait_for &= ~WAIT_TIME;
6604 6604
 			    th->status = THREAD_RUNNABLE;
6605 6605
 			    num_waiting_on_timer--;
6606  
-			    next = th;
  6606
+			    if (!next || next->priority < th->priority)
  6607
+				next = th;
6607 6608
 			} else if (th->delay < delay) {
6608 6609
 			    delay = th->delay;
6609 6610
 			}
@@ -7216,7 +7217,7 @@ rb_thread_start_timer()
7216 7217
 
7217 7218
     if (!thread_init) return;
7218 7219
     tval.it_interval.tv_sec = 0;
7219  
-    tval.it_interval.tv_usec = 50000;
  7220
+    tval.it_interval.tv_usec = 10000;
7220 7221
     tval.it_value = tval.it_interval;
7221 7222
     setitimer(ITIMER_VIRTUAL, &tval, NULL);
7222 7223
 }
16  hash.c
@@ -89,23 +89,7 @@ rb_any_hash(a)
89 89
 	break;
90 90
 
91 91
       case T_STRING:
92  
-#if 0
93 92
 	hval = rb_str_hash(a);
94  
-#else
95  
-	{
96  
-	    register const char *p = RSTRING(a)->ptr;
97  
-	    register int len = RSTRING(a)->len;
98  
-	    register unsigned int h = 0, g;
99  
-
100  
-	    while (len--) {
101  
-		h = ( h << 4 ) + *p++;
102  
-		if ( g = h & 0xF0000000 )
103  
-		    h ^= g >> 24;
104  
-		h &= ~g;
105  
-	    }
106  
-	    hval = h;
107  
-	}
108  
-#endif
109 93
 	break;
110 94
 
111 95
       default:
22  lib/mailread.rb
@@ -9,25 +9,25 @@ def initialize(f)
9 9
     @header = {}
10 10
     @body = []
11 11
     begin
12  
-      while f.gets()
13  
-	$_.chop!
14  
-	next if /^From /	# skip From-line
15  
-	break if /^$/		# end of header
  12
+      while line = f.gets()
  13
+	line.chop!
  14
+	next if /^From /=~line	# skip From-line
  15
+	break if /^$/=~line	# end of header
16 16
 
17  
-	if /^(\S+):\s*(.*)/
  17
+	if /^(\S+):\s*(.*)/=~line
18 18
 	  (attr = $1).capitalize!
19 19
 	  @header[attr] = $2
20 20
 	elsif attr
21  
-	  sub!(/^\s*/, '')
22  
-	  @header[attr] += "\n" + $_
  21
+	  line.sub!(/^\s*/, '')
  22
+	  @header[attr] += "\n" + line
23 23
 	end
24 24
       end
25 25
   
26  
-      return unless $_
  26
+      return unless line
27 27
 
28  
-      while f.gets()
29  
-	break if /^From /
30  
-	@body.push($_)
  28
+      while line = f.gets()
  29
+	break if /^From /=~line
  30
+	@body.push(line)
31 31
       end
32 32
     ensure
33 33
       f.close if opened
9  lib/open3.rb
@@ -43,13 +43,12 @@ def popen3(cmd)
43 43
 if $0 == __FILE__
44 44
   a = Open3.popen3("nroff -man")
45 45
   Thread.start do
46  
-    while gets
47  
-      a[0].print $_
  46
+    while line = gets
  47
+      a[0].print line
48 48
     end
49 49
     a[0].close
50 50
   end
51  
-  while a[1].gets
52  
-    print ":", $_
  51
+  while line = a[1].gets
  52
+    print ":", line
53 53
   end
54 54
 end
55  
-
72  st.c
@@ -62,7 +62,7 @@ static void rehash();
62 62
 #define EQUAL(table, x, y) ((*table->type->compare)(x, y) == 0)
63 63
 
64 64
 #define do_hash(key, table) (unsigned int)(*(table)->type->hash)((key))
65  
-#define do_hash_bin(key, table) (do_hash(key, table)%(table)->num_bins)
  65
+#define do_hash_bin(key, table) (do_hash(key, table)&(table)->num_bins)
66 66
 
67 67
 /*
68 68
  * MINSIZE is the minimum size of a dictionary.
@@ -112,6 +112,11 @@ new_size(size)
112 112
     int i, newsize;
113 113
 
114 114
 #if 1
  115
+    for (i=3; i<31; i++) {
  116
+	if ((1<<i) > size) return 1<<i;
  117
+    }
  118
+    return -1;
  119
+#else
115 120
     for (i = 0, newsize = MINSIZE;
116 121
 	 i < sizeof(primes)/sizeof(primes[0]);
117 122
 	 i++, newsize <<= 1)
@@ -120,14 +125,10 @@ new_size(size)
120 125
     }
121 126
     /* Ran out of polynomials */
122 127
     return -1;			/* should raise exception */
123  
-#else
124  
-    for (i=3; i<31; i++) {
125  
-	if ((1<<i) > size) return 1<<i;
126  
-    }
127  
-    return -1;
128 128
 #endif
129 129
 }
130 130
 
  131
+#ifdef HASH_LOG
131 132
 static int collision = 0;
132 133
 static int init_st = 0;
133 134
 
@@ -138,6 +139,7 @@ stat_col()
138 139
     fprintf(f, "collision: %d\n", collision);
139 140
     fclose(f);
140 141
 }
  142
+#endif
141 143
 
142 144
 st_table*
143 145
 st_init_table_with_size(type, size)
@@ -146,7 +148,7 @@ st_init_table_with_size(type, size)
146 148
 {
147 149
     st_table *tbl;
148 150
 
149  
-#if 0
  151
+#ifdef HASH_LOG
150 152
     if (init_st == 0) {
151 153
 	init_st = 1;
152 154
 	atexit(stat_col);
@@ -158,7 +160,7 @@ st_init_table_with_size(type, size)
158 160
     tbl = alloc(st_table);
159 161
     tbl->type = type;
160 162
     tbl->num_entries = 0;
161  
-    tbl->num_bins = size;
  163
+    tbl->num_bins = size-1;
162 164
     tbl->bins = (st_table_entry **)Calloc(size, sizeof(st_table_entry*));
163 165
 
164 166
     return tbl;
@@ -204,7 +206,7 @@ st_free_table(table)
204 206
     register st_table_entry *ptr, *next;
205 207
     int i;
206 208
 
207  
-    for(i = 0; i < table->num_bins; i++) {
  209
+    for(i = 0; i <= table->num_bins; i++) {
208 210
 	ptr = table->bins[i];
209 211
 	while (ptr != 0) {
210 212
 	    next = ptr->next;
@@ -219,11 +221,17 @@ st_free_table(table)
219 221
 #define PTR_NOT_EQUAL(table, ptr, hash_val, key) \
220 222
 ((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key)))
221 223
 
  224
+#ifdef HASH_LOG
  225
+#define COLLISION collision++
  226
+#else
  227
+#define COLLISION
  228
+#endif
  229
+
222 230
 #define FIND_ENTRY(table, ptr, hash_val, bin_pos) \
223  
-bin_pos = hash_val%(table)->num_bins;\
  231
+bin_pos = hash_val&(table)->num_bins;\
224 232
 ptr = (table)->bins[bin_pos];\
225 233
 if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\
226  
-    collision++;\
  234
+    COLLISION;\
227 235
     while (PTR_NOT_EQUAL(table, ptr->next, hash_val, key)) {\
228 236
 	ptr = ptr->next;\
229 237
     }\
@@ -253,9 +261,9 @@ st_lookup(table, key, value)
253 261
 #define ADD_DIRECT(table, key, value, hash_val, bin_pos)\
254 262
 {\
255 263
     st_table_entry *entry;\
256  
-    if (table->num_entries/table->num_bins > ST_DEFAULT_MAX_DENSITY) {\
  264
+    if (table->num_entries/(table->num_bins+1) > ST_DEFAULT_MAX_DENSITY) {\
257 265
 	rehash(table);\
258  
-        bin_pos = hash_val % table->num_bins;\
  266
+        bin_pos = hash_val & table->num_bins;\
259 267
     }\
260 268
     \
261 269
     entry = alloc(st_table_entry);\
@@ -298,7 +306,7 @@ st_add_direct(table, key, value)
298 306
     unsigned int hash_val, bin_pos;
299 307
 
300 308
     hash_val = do_hash(key, table);
301  
-    bin_pos = hash_val % table->num_bins;
  309
+    bin_pos = hash_val & table->num_bins;
302 310
     ADD_DIRECT(table, key, value, hash_val, bin_pos);
303 311
 }
304 312
 
@@ -310,14 +318,15 @@ rehash(table)
310 318
     int i, old_num_bins = table->num_bins, new_num_bins;
311 319
     unsigned int hash_val;
312 320
 
313  
-    new_num_bins = new_size(old_num_bins);
  321
+    new_num_bins = new_size(old_num_bins+1);
314 322
     new_bins = (st_table_entry**)Calloc(new_num_bins, sizeof(st_table_entry*));
315 323
 
316  
-    for(i = 0; i < old_num_bins; i++) {
  324
+    new_num_bins--;
  325
+    for(i = 0; i <= old_num_bins; i++) {
317 326
 	ptr = table->bins[i];
318 327
 	while (ptr != 0) {
319 328
 	    next = ptr->next;
320  
-	    hash_val = ptr->hash % new_num_bins;
  329
+	    hash_val = ptr->hash & new_num_bins;
321 330
 	    ptr->next = new_bins[hash_val];
322 331
 	    new_bins[hash_val] = ptr;
323 332
 	    ptr = next;
@@ -334,7 +343,7 @@ st_copy(old_table)
334 343
 {
335 344
     st_table *new_table;
336 345
     st_table_entry *ptr, *entry;
337  
-    int i, num_bins = old_table->num_bins;
  346
+    int i, num_bins = old_table->num_bins+1;
338 347
 
339 348
     new_table = alloc(st_table);
340 349
     if (new_table == 0) {
@@ -471,7 +480,7 @@ st_foreach(table, func, arg)
471 480
     enum st_retval retval;
472 481
     int i;
473 482
 
474  
-    for(i = 0; i < table->num_bins; i++) {
  483
+    for(i = 0; i <= table->num_bins; i++) {
475 484
 	last = 0;
476 485
 	for(ptr = table->bins[i]; ptr != 0;) {
477 486
 	    retval = (*func)(ptr->key, ptr->record, arg);
@@ -501,14 +510,35 @@ static int
501 510
 strhash(string)
502 511
     register char *string;
503 512
 {
504  
-    register int val = 0;
505 513
     register int c;
506 514
 
  515
+#ifdef HASH_ELFHASH
  516
+    register unsigned int h = 0, g;
  517
+
  518
+    while ((c = *string++) != '\0') {
  519
+	h = ( h << 4 ) + c;
  520
+	if ( g = h & 0xF0000000 )
  521
+	    h ^= g >> 24;
  522
+	h &= ~g;
  523
+    }
  524
+    return h;
  525
+#elif HASH_PERL
  526
+    register int val = 0;
  527
+
  528
+    while ((c = *string++) != '\0') {
  529
+	val = val*33 + c;
  530
+    }
  531
+
  532
+    return val + (val>>5);
  533
+#else
  534
+    register int val = 0;
  535
+
507 536
     while ((c = *string++) != '\0') {
508 537
 	val = val*997 + c;
509 538
     }
510 539
 
511  
-    return val;
  540
+    return val + (val>>5);
  541
+#endif
512 542
 }
513 543
 
514 544
 static int
39  string.c
@@ -421,29 +421,39 @@ rb_str_hash(str)
421 421
     register char *p = RSTRING(str)->ptr;
422 422
     register int key = 0;
423 423
 
424  
-#if 0
  424
+#ifdef HASH_ELFHASH
  425
+    register unsigned int g;
  426
+
  427
+    while (len--) {
  428
+	key = (key << 4) + *p++;
  429
+	if (g = key & 0xF0000000)
  430
+	    key ^= g >> 24;
  431
+	key &= ~g;
  432
+    }
  433
+#elif HASH_PERL
425 434
     if (ruby_ignorecase) {
426 435
 	while (len--) {
427  
-	    key = key*65599 + toupper(*p);
  436
+	    key = key*33 + toupper(*p);
428 437
 	    p++;
429 438
 	}
430 439
     }
431 440
     else {
432 441
 	while (len--) {
433  
-	    key = key*65599 + *p;
434  
-	    p++;
  442
+	    key = key*33 + *p++;
435 443
 	}
436 444
     }
  445
+    key = key + (key>>5);
437 446
 #else
438 447
     if (ruby_ignorecase) {
439 448
 	while (len--) {
440  
-	    key = key*33 + toupper(*p);
  449
+	    key = key*65599 + toupper(*p);
441 450
 	    p++;
442 451
 	}
443 452
     }
444 453
     else {
445 454
 	while (len--) {
446  
-	    key = key*33 + *p++;
  455
+	    key = key*65599 + *p;
  456
+	    p++;
447 457
 	}
448 458
     }
449 459
     key = key + (key>>5);
@@ -943,16 +953,13 @@ rb_str_aset_m(argc, argv, str)
943 953
     VALUE *argv;
944 954
     VALUE str;
945 955
 {
946  
-    VALUE arg1, arg2, arg3;
947  
-
948 956
     rb_str_modify(str);
949  
-
950  
-    if (rb_scan_args(argc, argv, "21", &arg1, &arg2, &arg3) == 3) {
  957
+    if (argc == 3) {
951 958
 	int beg, len;
952 959
 
953  
-	if (TYPE(arg3) != T_STRING) arg3 = rb_str_to_str(arg3);
954  
-	beg = NUM2INT(arg1);
955  
-	len = NUM2INT(arg2);
  960
+	if (TYPE(argv[2]) != T_STRING) argv[2] = rb_str_to_str(argv[2]);
  961
+	beg = NUM2INT(argv[0]);
  962
+	len = NUM2INT(argv[1]);
956 963
 	if (len < 0) rb_raise(rb_eIndexError, "negative length %d", len);
957 964
 	if (beg < 0) {
958 965
 	    beg += RSTRING(str)->len;
@@ -966,10 +973,10 @@ rb_str_aset_m(argc, argv, str)
966 973
 	if (beg + len > RSTRING(str)->len) {
967 974
 	    len = RSTRING(str)->len - beg;
968 975
 	}
969  
-	rb_str_replace(str, beg, len, arg3);
970  
-	return arg3;
  976
+	rb_str_replace(str, beg, len, argv[2]);
  977
+	return argv[2];
971 978
     }
972  
-    return rb_str_aset(str, arg1, arg2);
  979
+    return rb_str_aset(str, argv[0], argv[1]);
973 980
 }
974 981
 
975 982
 static VALUE
4  version.h
... ...
@@ -1,4 +1,4 @@
1 1
 #define RUBY_VERSION "1.5.2"
2  
-#define RUBY_RELEASE_DATE "2000-02-23"
  2
+#define RUBY_RELEASE_DATE "2000-02-25"
3 3
 #define RUBY_VERSION_CODE 152
4  
-#define RUBY_RELEASE_CODE 20000223
  4
+#define RUBY_RELEASE_CODE 20000225

0 notes on commit a4fce2f

Please sign in to comment.
Something went wrong with that request. Please try again.