Changeset 1907 for trunk/src/kmk/variable.c
- Timestamp:
- Oct 21, 2008, 11:29:00 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/variable.c
r1902 r1907 442 442 443 443 444 #ifdef KMK /* bird: speed */ 445 MY_INLINE struct variable * 446 lookup_cached_variable (const char *name) 447 { 448 const struct variable_set_list *setlist = current_variable_set_list; 449 struct hash_table *ht; 450 unsigned int hash_1; 451 unsigned int hash_2; 452 unsigned int idx; 453 struct variable *v; 454 455 /* first set, first entry, both unrolled. */ 456 457 if (setlist->set == &global_variable_set) 458 { 459 v = (struct variable *) strcache2_get_user_val (&variable_strcache, name); 460 if (MY_PREDICT_TRUE (v)) 461 return MY_PREDICT_FALSE (v->special) ? handle_special_var (v) : v; 462 assert (setlist->next == 0); 463 return 0; 464 } 465 466 hash_1 = strcache2_get_ptr_hash (&variable_strcache, name); 467 ht = &setlist->set->table; 468 idx = hash_1 & (ht->ht_size - 1); 469 v = ht->ht_vec[idx]; 470 if (v != 0) 471 { 472 if ( (void *)v != hash_deleted_item 473 && v->name == name) 474 return MY_PREDICT_FALSE (v->special) ? handle_special_var (v) : v; 475 476 /* the rest of the loop */ 477 hash_2 = strcache2_get_hash1 (&variable_strcache, name) | 1; 478 for (;;) 479 { 480 idx += hash_2; 481 idx &= (ht->ht_size - 1); 482 v = (struct variable *) ht->ht_vec[idx]; 483 ht->ht_collisions++; /* there are hardly any deletions, so don't bother with not counting deleted clashes. */ 484 485 if (v == 0) 486 break; 487 if ( (void *)v != hash_deleted_item 488 && v->name == name) 489 return MY_PREDICT_FALSE (v->special) ? handle_special_var (v) : v; 490 } /* inner collision loop */ 491 } 492 else 493 hash_2 = strcache2_get_hash1 (&variable_strcache, name) | 1; 494 495 496 /* The other sets, if any. */ 497 498 setlist = setlist->next; 499 while (setlist) 500 { 501 if (setlist->set == &global_variable_set) 502 { 503 v = (struct variable *) strcache2_get_user_val (&variable_strcache, name); 504 if (MY_PREDICT_TRUE (v)) 505 return MY_PREDICT_FALSE (v->special) ? handle_special_var (v) : v; 506 assert (setlist->next == 0); 507 return 0; 508 } 509 510 /* first iteration unrolled */ 511 ht = &setlist->set->table; 512 idx = hash_1 & (ht->ht_size - 1); 513 v = ht->ht_vec[idx]; 514 if (v != 0) 515 { 516 if ( (void *)v != hash_deleted_item 517 && v->name == name) 518 return MY_PREDICT_FALSE (v->special) ? handle_special_var (v) : v; 519 520 /* the rest of the loop */ 521 for (;;) 522 { 523 idx += hash_2; 524 idx &= (ht->ht_size - 1); 525 v = (struct variable *) ht->ht_vec[idx]; 526 ht->ht_collisions++; /* see reason above */ 527 528 if (v == 0) 529 break; 530 if ( (void *)v != hash_deleted_item 531 && v->name == name) 532 return MY_PREDICT_FALSE (v->special) ? handle_special_var (v) : v; 533 } /* inner collision loop */ 534 } 535 536 /* next */ 537 setlist = setlist->next; 538 } 539 540 return 0; 541 } 542 543 # ifndef NDEBUG 544 struct variable * 545 lookup_variable_for_assert (const char *name, unsigned int length) 546 { 547 const struct variable_set_list *setlist; 548 struct variable var_key; 549 var_key.name = name; 550 var_key.length = length; 551 552 for (setlist = current_variable_set_list; 553 setlist != 0; setlist = setlist->next) 554 { 555 struct variable *v; 556 v = (struct variable *) hash_find_item_strcached (&setlist->set->table, &var_key); 557 if (v) 558 return MY_PREDICT_FALSE (v->special) ? handle_special_var (v) : v; 559 } 560 return 0; 561 } 562 # endif /* !NDEBUG */ 563 #endif /* KMK - need for speed */ 564 444 565 /* Lookup a variable whose name is a string starting at NAME 445 566 and with LENGTH chars. NAME need not be null-terminated. … … 450 571 lookup_variable (const char *name, unsigned int length) 451 572 { 573 #ifndef KMK 452 574 const struct variable_set_list *setlist; 453 575 struct variable var_key; 454 # ifdef KMK455 unsigned int hash_2 = 0;456 #endif 576 #else /* KMK */ 577 struct variable *v; 578 #endif /* KMK */ 457 579 #ifdef CONFIG_WITH_STRCACHE2 458 580 const char *cached_name; … … 465 587 name = cached_name; 466 588 #endif /* CONFIG_WITH_STRCACHE2 */ 589 #ifndef KMK 467 590 468 591 var_key.name = (char *) name; … … 472 595 setlist != 0; setlist = setlist->next) 473 596 { 474 #ifdef KMK /* bird: speed */475 struct hash_table *ht = &setlist->set->table;476 unsigned int hash_1 = strcache2_get_ptr_hash (&variable_strcache, name);477 struct variable *v;478 479 ht->ht_lookups++;480 for (;;)481 {482 hash_1 &= (ht->ht_size - 1);483 v = (struct variable *)ht->ht_vec[hash_1];484 485 if (v == 0)486 {487 # ifndef NDEBUG488 struct variable *v2 = (struct variable *) hash_find_item_strcached ((struct hash_table *) &setlist->set->table, &var_key);489 assert (v2 == 0);490 # endif491 break;492 }493 if ((void *)v != hash_deleted_item)494 {495 if (v->name == cached_name)496 {497 # ifndef NDEBUG498 struct variable *v2 = (struct variable *) hash_find_item_strcached ((struct hash_table *) &setlist->set->table, &var_key);499 assert (v2 == v);500 # endif501 return v->special ? handle_special_var (v) : v;502 }503 ht->ht_collisions++;504 }505 if (!hash_2)506 hash_2 = strcache2_get_hash1 (&variable_strcache, name) | 1;507 hash_1 += hash_2;508 }509 510 #else /* !KMK */511 597 const struct variable_set *set = setlist->set; 512 598 struct variable *v; … … 519 605 if (v) 520 606 return v->special ? handle_special_var (v) : v; 521 #endif /* !KMK */ 522 } 523 607 } 608 609 #else /* KMK - need for speed */ 610 611 v = lookup_cached_variable (name); 612 assert (lookup_variable_for_assert(name, length) == v); 613 #ifdef VMS 614 if (v) 615 #endif 616 return v; 617 #endif /* KMK - need for speed */ 524 618 #ifdef VMS 525 619 /* since we don't read envp[] on startup, try to get the … … 578 672 #endif /* VMS */ 579 673 674 #if !defined (KMK) || defined(VMS) 580 675 return 0; 676 #endif 581 677 } 582 678
Note:
See TracChangeset
for help on using the changeset viewer.