[webkit-changes] cvs commit: WebCore/khtml/misc hashmap.h

Darin darin at opensource.apple.com
Sat Aug 6 09:28:44 PDT 2005


darin       05/08/06 09:28:43

  Modified:    .        ChangeLog
               khtml/misc hashmap.h
  Log:
          Reviewed by Dave Hyatt.
  
          - added a "set" operation to HashMap for cases where you want to either insert or
            modify an existing map entry; the "set" name is based on symmetry with get, and also on
            the naming used for similar operations in CFDictionary.
  
          * khtml/misc/hashmap.h: Small tweak to insert and added set.
  
  Revision  Changes    Path
  1.4532    +10 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.4531
  retrieving revision 1.4532
  diff -u -r1.4531 -r1.4532
  --- ChangeLog	6 Aug 2005 16:27:25 -0000	1.4531
  +++ ChangeLog	6 Aug 2005 16:28:39 -0000	1.4532
  @@ -2,6 +2,16 @@
   
           Reviewed by Dave Hyatt.
   
  +        - added a "set" operation to HashMap for cases where you want to either insert or
  +          modify an existing map entry; the "set" name is based on symmetry with get, and also on
  +          the naming used for similar operations in CFDictionary.
  +
  +        * khtml/misc/hashmap.h: Small tweak to insert and added set.
  +
  +2005-08-06  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Dave Hyatt.
  +
           - made a small improvement to how Windows Latin-1 characters are handled in the tokenizer
   
           * khtml/html/htmltokenizer.cpp:
  
  
  
  1.3       +11 -5     WebCore/khtml/misc/hashmap.h
  
  Index: hashmap.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/misc/hashmap.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- hashmap.h	9 Jul 2005 20:19:16 -0000	1.2
  +++ hashmap.h	6 Aug 2005 16:28:43 -0000	1.3
  @@ -64,7 +64,8 @@
       bool contains(const KeyType& key) const;
       MappedType get(const KeyType &key) const;
   
  -    std::pair<iterator, bool> insert(const KeyType &key, const MappedType &mapped);
  +    std::pair<iterator, bool> insert(const KeyType &key, const MappedType &mapped); // no effect if key is already present
  +    std::pair<iterator, bool> set(const KeyType &key, const MappedType &mapped); // replaces if key is already present
   
       void remove(const KeyType& key);
       void remove(iterator it);
  @@ -138,12 +139,17 @@
   std::pair<typename HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::iterator, bool> HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::insert(const KeyType &key, const MappedType &mapped) 
   {
       pair<iterator, bool> result = m_impl.insert(ValueType(key, mapped));
  -    iterator it = result.first;
  -    
       // insert won't change anything if the key is already there
       if (!result.second)
  -        it->second = mapped;
  -    
  +        result.first->second = mapped;    
  +    return result;
  +}
  +
  +template<typename Key, typename Mapped, typename HashFunctions, typename KeyTraits, typename MappedTraits>
  +std::pair<typename HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::iterator, bool> HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::set(const KeyType &key, const MappedType &mapped) 
  +{
  +    pair<iterator, bool> result = m_impl.insert(ValueType(key, mapped));
  +    result.first->second = mapped;
       return result;
   }
   
  
  
  



More information about the webkit-changes mailing list