Ignore:
Timestamp:
Dec 5, 2008, 5:05:06 PM (17 years ago)
Author:
[email protected]
Message:

<rdar://problem/6331749> Provide a mechanism to disable perfect hashing in the DOM at build time

Reviewed by Darin Adler.

Initial patch by Yosen Lin. Adapted for ToT WebKit by David Kilzer.

Added back the code that generates a "compact" hash (instead of a
perfect hash) as a build-time option using the
ENABLE(PERFECT_HASH_SIZE) macro as defined in Lookup.h.

JavaScriptCore:

  • create_hash_table: Rename variables to differentiate perfect hash values from compact hash values. Added back code to compute compact hash tables. Generate both hash table sizes and emit conditionalized code based on ENABLE(PERFECT_HASH_SIZE).
  • runtime/Lookup.cpp: (JSC::HashTable::createTable): Added version of createTable() for use with compact hash tables. (JSC::HashTable::deleteTable): Updated to work with compact hash tables.
  • runtime/Lookup.h: Defined ENABLE(PERFECT_HASH_SIZE) macro here. (JSC::HashEntry::initialize): Set m_next to zero when using compact hash tables. (JSC::HashEntry::setNext): Added for compact hash tables. (JSC::HashEntry::next): Added for compact hash tables. (JSC::HashTable::entry): Added version of entry() for use with compact hash tables.
  • runtime/Structure.cpp: (JSC::Structure::getEnumerablePropertyNames): Updated to work with compact hash tables.

WebCore:

  • bindings/scripts/CodeGeneratorJS.pm: (GenerateImplementation): Compute the number of elements that will be stored in each hash table and pass it to GenerateHashTable(). (GenerateHashTable): Added new second parameter representing the number of elements to store in the compact hash table. Added back code to compute compact hash tables. Generate both hash table sizes and emit conditionalized code based on ENABLE(PERFECT_HASH_SIZE).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/create_hash_table

    r38155 r39056  
    4747my $inside = 0;
    4848my $name;
    49 my $size;
     49my $pefectHashSize;
     50my $compactSize;
     51my $compactHashSizeMask;
    5052my $banner = 0;
    51 sub calcSize();
     53sub calcPerfectHashSize();
     54sub calcCompactHashSize();
    5255sub output();
    5356sub jsc_ucfirst($);
     
    6669        }
    6770    } elsif (/^\@end\s*$/ && $inside) {
    68         calcSize();
     71        calcPerfectHashSize();
     72        calcCompactHashSize();
    6973        output();
    7074
     
    117121sub ceilingToPowerOf2
    118122{
    119     my ($size) = @_;
     123    my ($pefectHashSize) = @_;
    120124
    121125    my $powerOf2 = 1;
    122     while ($size > $powerOf2) {
     126    while ($pefectHashSize > $powerOf2) {
    123127        $powerOf2 <<= 1;
    124128    }
     
    127131}
    128132
    129 sub calcSize()
     133sub calcPerfectHashSize()
    130134{
    131135tableSizeLoop:
    132     for ($size = ceilingToPowerOf2(scalar @keys); ; $size += $size) {
     136    for ($pefectHashSize = ceilingToPowerOf2(scalar @keys); ; $pefectHashSize += $pefectHashSize) {
    133137        my @table = ();
    134138        foreach my $key (@keys) {
    135             my $h = hashValue($key) % $size;
     139            my $h = hashValue($key) % $pefectHashSize;
    136140            next tableSizeLoop if $table[$h];
    137141            $table[$h] = 1;
     
    144148    my ($value, $distance) = @_;
    145149    return (($value << $distance) & 0xFFFFFFFF);
     150}
     151
     152sub calcCompactHashSize()
     153{
     154    my @table = ();
     155    my @links = ();
     156    my $compactHashSize = ceilingToPowerOf2(2 * @keys);
     157    $compactHashSizeMask = $compactHashSize - 1;
     158    $compactSize = $compactHashSize;
     159    my $collisions = 0;
     160    my $maxdepth = 0;
     161    my $i = 0;
     162    foreach my $key (@keys) {
     163        my $depth = 0;
     164        my $h = hashValue($key) % $compactHashSize;
     165        while (defined($table[$h])) {
     166            if (defined($links[$h])) {
     167                $h = $links[$h];
     168                $depth++;
     169            } else {
     170                $collisions++;
     171                $links[$h] = $compactSize;
     172                $h = $compactSize;
     173                $compactSize++;
     174            }
     175        }
     176        $table[$h] = $i;
     177        $i++;
     178        $maxdepth = $depth if ( $depth > $maxdepth);
     179    }
    146180}
    147181
     
    237271    print "   { 0, 0, 0, 0 }\n";
    238272    print "};\n\n";
    239     print "extern const struct HashTable $name = ";
    240     print "\{ ", $size - 1, ", $nameEntries, 0 \};\n\n";
     273    print "extern const struct HashTable $name =\n";
     274    print "#if ENABLE(PERFECT_HASH_SIZE)\n";
     275    print "    \{ ", $pefectHashSize - 1, ", $nameEntries, 0 \};\n";
     276    print "#else\n";
     277    print "    \{ $compactSize, $compactHashSizeMask, $nameEntries, 0 \};\n";
     278    print "#endif\n\n";
    241279    print "} // namespace\n";
    242280}
Note: See TracChangeset for help on using the changeset viewer.