Ignore:
Timestamp:
Dec 22, 2005, 5:52:43 PM (19 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Darin.

The changes for support are relatively simple, but I also made extensive changes to
avoid copying, so that there isn't refcount thrash when you put RefPtrs into a HashMap.

  • kxmlcore/HashTable.h: (KXMLCore::swap): specialize swap for pairs, to swap elements individually, so that excess copies can be avoided. (KXMLCore::Mover::move): Template function to either copy or swap, used when transferring elements from old table to new. (KXMLCore::IdentityHashTranslator::hash): The old "converting lookup" templates that took two or three function parameters now take a class parameter, this is the class used to do a normal lookup. (KXMLCore::IdentityHashTranslator::equal): Ditto. (KXMLCore::IdentityHashTranslator::translate): Ditto. Translate now takes a reference to write into instead of returning a value to avoid redundant copies. (KXMLCore::HashTable::~HashTable): Use deallocateTable instead of freeing directly. (KXMLCore::HashTable::insert): Based on HashTranslator now instead of separate functions. Added a FIXME about a remaining rare excess copy. (KXMLCore::HashTable::isEmptyBucket): Use KeyTraits directly instead of unwrapping the key from Traits, to avoid creating and destroying pair, which copies. (KXMLCore::HashTable::isDeletedBucket): ditto (KXMLCore::HashTable::lookup): Use HashTranslator now instead of separate functions. (KXMLCore::HashTable::initializeBucket): Renamed from emptyBucket. Use placement new to work right for non-POD types. (KXMLCore::HashTable::deleteBucket): Use assignDeleted to avoid excess copies. (KXMLCore::HashTable::reinsert): use Mover template to copy or swap as appropriate (KXMLCore::HashTable::allocateTable): Initialize every bucket if calloc won't do. (KXMLCore::HashTable::deallocateTable): Destruct every bucket if needed. (KXMLCore::HashTable::rehash): Avoid copy before reinserting, so that swap can do its magic. (KXMLCore::HashTable::clear): use deallocateTable instead of freeing directly. (KXMLCore::HashTable::HashTable): be more dumb when copying to ensure that non-POD types work right
  • kxmlcore/HashFunctions.h: (KXMLCore::PointerHash): Specialize PointerHash for RefPtr
  • kxmlcore/HashMap.h: (KXMLCore::extractFirst): Return a reference not a full object to avoid copies. (KXMLCore::HashMapTranslator::hash): Use a special translator for insertion to defer making the pair as long as possible, thus avoiding needless copies. (KXMLCore::HashMapTranslator::equal): ditto (KXMLCore::HashMapTranslator::translate): ditto (KXMLCore::::inlineAdd): Shared by set and add to insert using HashMapTranslator (KXMLCore::::set): Use inlineAdd (KXMLCore::::add): Use inlineAdd
  • kxmlcore/HashMapPtrSpec.h: (KXMLCore::): Pass KeyTraits along
  • kxmlcore/HashSet.h: (KXMLCore::identityExtract): Return a reference not a full object to avoid copies. (KXMLCore::HashSetTranslatorAdapter::hash): Redo adapter stuff to work with the new HashTranslator approach. (KXMLCore::HashSetTranslatorAdapter::equal): ditto (KXMLCore::HashSetTranslatorAdapter::translate): ditto (KXMLCore::::insert): ditto
  • kxmlcore/HashTraits.h: (KXMLCore::GenericHashTraits): This is intended be used as a base class for customized traits: sensible defaults. (KXMLCore::): Use it a bunch (KXMLCore::assignDeleted): template function to allow pairs to be assigned the deleted value w/o excess copies. (KXMLCore::PairHashTraits::emptyValue): Updated (KXMLCore::PairHashTraits::deletedValue): Updated (KXMLCore::PairHashTraits::assignDeletedValue): part of assignDeleted hack (KXMLCore::DeletedValueAssigner::assignDeletedValue): Use template magic to either use use deletedValue or assignDeletedValue for the cases where we care.
  • kxmlcore/RefPtr.h: (KXMLCore::RefPtr::swap): Added swap method. (KXMLCore::swap): Added swap free function.
  • kjs/identifier.cpp: (KJS::CStringTranslator::hash): Use new HashTranslator class approach to alternate type based insertion. (KJS::CStringTranslator::equal): ditto (KJS::CStringTranslator::translate): ditto (KJS::Identifier::add): ditto (KJS::UCharBufferTranslator::hash): ditto (KJS::UCharBufferTranslator::equal): ditto (KJS::UCharBufferTranslator::translate): ditto
  • irrelevant change:
  • kjs/array_object.cpp: (ArrayProtoFunc::callAsFunction): Removed a stray space.

WebCore:

Reviewed by Darin.

  • update for new HashTranslator stuff
  • khtml/xml/dom_atomicstring.cpp: (DOM::CStringTranslator::hash): (DOM::CStringTranslator::equal): (DOM::CStringTranslator::translate): (DOM::AtomicString::equal): (DOM::AtomicString::add): (DOM::QCharBufferTranslator::hash): (DOM::QCharBufferTranslator::equal): (DOM::QCharBufferTranslator::translate):
  • khtml/xml/dom_qname.cpp: (DOM::QNameComponentsTranslator::hash): (DOM::QNameComponentsTranslator::equal): (DOM::QNameComponentsTranslator::translate): (DOM::QualifiedName::QualifiedName):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r11684 r11739  
    9999}
    100100
    101 inline unsigned hash(const char* const& c)
    102 {
    103     return UString::Rep::computeHash(c);
    104 }
    105 
    106 inline bool equal(UString::Rep* const& r, const char* const& s)
    107 {
    108     return Identifier::equal(r, s);
    109 }
    110 
    111 inline UString::Rep *convert(const char* const& c, unsigned hash)
    112 {
    113     int length = strlen(c);
    114     UChar *d = static_cast<UChar *>(fastMalloc(sizeof(UChar) * length));
    115     for (int i = 0; i != length; i++)
    116         d[i] = c[i];
    117    
    118     UString::Rep *r = UString::Rep::create(d, length).release();
    119     r->isIdentifier = 1;
    120     r->rc = 0;
    121     r->_hash = hash;
    122 
    123     return r;
    124 }
     101struct CStringTranslator
     102{
     103    static unsigned hash(const char *c)
     104    {
     105        return UString::Rep::computeHash(c);
     106    }
     107
     108    static bool equal(UString::Rep *r, const char *s)
     109    {
     110        return Identifier::equal(r, s);
     111    }
     112
     113    static void translate(UString::Rep*& location, const char *c, unsigned hash)
     114    {
     115        int length = strlen(c);
     116        UChar *d = static_cast<UChar *>(fastMalloc(sizeof(UChar) * length));
     117        for (int i = 0; i != length; i++)
     118            d[i] = c[i];
     119       
     120        UString::Rep *r = UString::Rep::create(d, length).release();
     121        r->isIdentifier = 1;
     122        r->rc = 0;
     123        r->_hash = hash;
     124
     125        location = r;
     126    }
     127};
    125128
    126129PassRefPtr<UString::Rep> Identifier::add(const char *c)
     
    132135        return pass(&UString::Rep::empty);
    133136   
    134     return pass(*identifierTable().insert<const char *, hash, KJS::equal, convert>(c).first);
     137    return pass(*identifierTable().insert<const char *, CStringTranslator>(c).first);
    135138}
    136139
     
    140143};
    141144
    142 inline unsigned hash(const UCharBuffer& buf)
    143 {
    144     return UString::Rep::computeHash(buf.s, buf.length);
    145 }
    146 
    147 inline bool equal(UString::Rep* const& str, const UCharBuffer& buf)
    148 {
    149     return Identifier::equal(str, buf.s, buf.length);
    150 }
    151 
    152 inline UString::Rep *convert(const UCharBuffer& buf, unsigned hash)
    153 {
    154     UChar *d = static_cast<UChar *>(fastMalloc(sizeof(UChar) * buf.length));
    155     for (unsigned i = 0; i != buf.length; i++)
    156         d[i] = buf.s[i];
    157 
    158     UString::Rep *r = UString::Rep::create(d, buf.length).release();
    159     r->isIdentifier = 1;
    160     r->rc = 0;
    161     r->_hash = hash;
    162 
    163     return r;
    164 }
     145struct UCharBufferTranslator
     146{
     147    static unsigned hash(const UCharBuffer& buf)
     148    {
     149        return UString::Rep::computeHash(buf.s, buf.length);
     150    }
     151
     152    static bool equal(UString::Rep *str, const UCharBuffer& buf)
     153    {
     154        return Identifier::equal(str, buf.s, buf.length);
     155    }
     156
     157    static void translate(UString::Rep *& location, const UCharBuffer& buf, unsigned hash)
     158    {
     159        UChar *d = static_cast<UChar *>(fastMalloc(sizeof(UChar) * buf.length));
     160        for (unsigned i = 0; i != buf.length; i++)
     161            d[i] = buf.s[i];
     162       
     163        UString::Rep *r = UString::Rep::create(d, buf.length).release();
     164        r->isIdentifier = 1;
     165        r->rc = 0;
     166        r->_hash = hash;
     167       
     168        location = r;
     169    }
     170};
    165171
    166172PassRefPtr<UString::Rep> Identifier::add(const UChar *s, int length)
     
    170176   
    171177    UCharBuffer buf = {s, length};
    172     return pass(*identifierTable().insert<UCharBuffer, hash, KJS::equal, convert>(buf).first);
     178    return pass(*identifierTable().insert<UCharBuffer, UCharBufferTranslator>(buf).first);
    173179}
    174180
Note: See TracChangeset for help on using the changeset viewer.