[webkit-changes] cvs commit: WebCore/khtml/ecma kjs_binding.cpp

Maciej mjs at opensource.apple.com
Tue Dec 13 03:06:11 PST 2005


mjs         05/12/13 03:06:11

  Modified:    .        ChangeLog
               JavaScriptCore.xcodeproj project.pbxproj
               kjs      collector.cpp collector.h protect.h value.h
               kxmlcore HashFunctions.h HashMap.h HashMapPtrSpec.h
               .        ChangeLog
               khtml/ecma kjs_binding.cpp
  Added:       kxmlcore HashCountedSet.h
               ForwardingHeaders/kxmlcore HashCountedSet.h
  Removed:     kjs      protected_values.cpp protected_values.h
  Log:
  JavaScriptCore:
  
          Reviewed by Eric.
  
  	- added a new HashCountedSet class for the common pattern of mapping items to counts that can change
  
          * kxmlcore/HashCountedSet.h: Added.
          (KXMLCore::HashCountedSet::*): Implemented, on top of HashMap.
          * kxmlcore/HashMap.h:
          (KXMLCore::HashMap::add): New method - does not replace existing value if key already present
  	but otherwise like set().
          (KXMLCore::HashMap::set): Improved comments.
          * kxmlcore/HashMapPtrSpec.h:
          (KXMLCore::HashMap::add): Added to specializations too.
          * JavaScriptCore.xcodeproj/project.pbxproj: Add new  file.
          * kxmlcore/HashFunctions.h: Added include of stdint.h
  
  	- replaced the custom hashtable for values protected from GC with HashCountedSet
  
          * kjs/collector.cpp:
          (KJS::Collector::protect): Moved code here from ProtectedValues::increaseProtectCount
  	since the code is so simple now.
          (KJS::Collector::unprotect): Ditto for ProtectedValues::decreaseProtectCount.
          (KJS::Collector::markProtectedObjects): Updated for new way of doing things, now
  	simpler and safer.
          (KJS::Collector::numReferencedObjects): ditto
          (KJS::Collector::rootObjectClasses): ditto
          * kjs/collector.h: Added protect and unprotect static methods
          * kjs/protect.h:
          (KJS::gcProtect): Updated for removal of ProtectedValues class
          (KJS::gcUnprotect): likewise
          * kjs/protected_values.cpp: Removed.
          * kjs/protected_values.h: Removed.
  
  WebCore:
  
          Reviewed by Eric.
  
          - updated for new HashCountedSet class
  
          * ForwardingHeaders/kxmlcore/HashCountedSet.h: Added forwarding header.
          * khtml/ecma/kjs_binding.cpp: Moved #define to disable pointer specialization higher
  	in the file.
  
  Revision  Changes    Path
  1.899     +34 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.898
  retrieving revision 1.899
  diff -u -r1.898 -r1.899
  --- ChangeLog	11 Dec 2005 02:05:29 -0000	1.898
  +++ ChangeLog	13 Dec 2005 11:06:01 -0000	1.899
  @@ -1,3 +1,37 @@
  +2005-12-12  Maciej Stachowiak  <mjs at apple.com>
  +
  +        Reviewed by Eric.
  +
  +	- added a new HashCountedSet class for the common pattern of mapping items to counts that can change
  +	
  +        * kxmlcore/HashCountedSet.h: Added.
  +        (KXMLCore::HashCountedSet::*): Implemented, on top of HashMap.
  +        * kxmlcore/HashMap.h:
  +        (KXMLCore::HashMap::add): New method - does not replace existing value if key already present
  +	but otherwise like set().
  +        (KXMLCore::HashMap::set): Improved comments.
  +        * kxmlcore/HashMapPtrSpec.h:
  +        (KXMLCore::HashMap::add): Added to specializations too.
  +        * JavaScriptCore.xcodeproj/project.pbxproj: Add new  file.
  +        * kxmlcore/HashFunctions.h: Added include of stdint.h
  +	
  +	- replaced the custom hashtable for values protected from GC with HashCountedSet
  +
  +        * kjs/collector.cpp:
  +        (KJS::Collector::protect): Moved code here from ProtectedValues::increaseProtectCount
  +	since the code is so simple now.
  +        (KJS::Collector::unprotect): Ditto for ProtectedValues::decreaseProtectCount.
  +        (KJS::Collector::markProtectedObjects): Updated for new way of doing things, now
  +	simpler and safer.
  +        (KJS::Collector::numReferencedObjects): ditto
  +        (KJS::Collector::rootObjectClasses): ditto
  +        * kjs/collector.h: Added protect and unprotect static methods
  +        * kjs/protect.h:
  +        (KJS::gcProtect): Updated for removal of ProtectedValues class
  +        (KJS::gcUnprotect): likewise
  +        * kjs/protected_values.cpp: Removed.
  +        * kjs/protected_values.h: Removed.
  +
   2005-12-10  Darin Adler  <darin at apple.com>
   
           Rubber stamped by Maciej.
  
  
  
  1.28      +4 -8      JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
  
  Index: project.pbxproj
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- project.pbxproj	6 Dec 2005 09:21:02 -0000	1.27
  +++ project.pbxproj	13 Dec 2005 11:06:03 -0000	1.28
  @@ -33,6 +33,7 @@
   		6557E8F808EA5D4D0049CDFC /* HashMapPtrSpec.h in Headers */ = {isa = PBXBuildFile; fileRef = 6557E8F708EA5D4D0049CDFC /* HashMapPtrSpec.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		65621E6D089E859700760F35 /* property_slot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65621E6B089E859700760F35 /* property_slot.cpp */; };
   		65621E6E089E859700760F35 /* property_slot.h in Headers */ = {isa = PBXBuildFile; fileRef = 65621E6C089E859700760F35 /* property_slot.h */; settings = {ATTRIBUTES = (Private, ); }; };
  +		657EEBC0094E445E008C9C7B /* HashCountedSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 657EEBBF094E445E008C9C7B /* HashCountedSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		6580F796094070560082C219 /* PassRefPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 6580F795094070560082C219 /* PassRefPtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		65C647B4093EF8D60022C380 /* RefPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 65C647B3093EF8D60022C380 /* RefPtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		65D7D19C08F10B5B0015ABD8 /* FastMallocInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 65D7D19B08F10B5B0015ABD8 /* FastMallocInternal.h */; };
  @@ -115,7 +116,6 @@
   		932F5B840822A1C700736975 /* NP_jsobject.h in Headers */ = {isa = PBXBuildFile; fileRef = 517BE7F40610E39600221947 /* NP_jsobject.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		932F5B850822A1C700736975 /* npruntime.h in Headers */ = {isa = PBXBuildFile; fileRef = 5199B1BE061B65BC0070C006 /* npruntime.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		932F5B880822A1C700736975 /* protect.h in Headers */ = {isa = PBXBuildFile; fileRef = 65C02FBB0637462A003E7EE6 /* protect.h */; settings = {ATTRIBUTES = (Private, ); }; };
  -		932F5B890822A1C700736975 /* protected_values.h in Headers */ = {isa = PBXBuildFile; fileRef = 650B68D90639033F009D42DE /* protected_values.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		932F5B8A0822A1C700736975 /* WebScriptObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 51863F6F065420E800E9E8DD /* WebScriptObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		932F5B8B0822A1C700736975 /* WebScriptObjectPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 700DA117065984CE00747C0B /* WebScriptObjectPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		932F5B8C0822A1C700736975 /* npapi.h in Headers */ = {isa = PBXBuildFile; fileRef = 51CA3B4F06CC2166005600E3 /* npapi.h */; settings = {ATTRIBUTES = (Private, ); }; };
  @@ -174,7 +174,6 @@
   		932F5BC90822A1C700736975 /* c_utility.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5182A4FB06010F8200CBD2F2 /* c_utility.cpp */; };
   		932F5BCA0822A1C700736975 /* c_class.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5182A53A06012C3000CBD2F2 /* c_class.cpp */; };
   		932F5BCB0822A1C700736975 /* npruntime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5199B1BD061B65BC0070C006 /* npruntime.cpp */; };
  -		932F5BCD0822A1C700736975 /* protected_values.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 650B68D80639033F009D42DE /* protected_values.cpp */; };
   		932F5BCE0822A1C700736975 /* WebScriptObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51863FC406542D3100E9E8DD /* WebScriptObject.mm */; };
   		932F5BCF0822A1C700736975 /* jni_objc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 517EF37306D695930007C1BA /* jni_objc.mm */; };
   		932F5BD00822A1C700736975 /* softlinking.c in Sources */ = {isa = PBXBuildFile; fileRef = 8442A376074175C2000AE2ED /* softlinking.c */; };
  @@ -321,8 +320,6 @@
   		51F0EC1005C86F3500E6DF1B /* objc_header.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = objc_header.h; path = bindings/objc/objc_header.h; sourceTree = "<group>"; };
   		51F0EC9605C88DC700E6DF1B /* objc_utility.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = objc_utility.h; path = bindings/objc/objc_utility.h; sourceTree = "<group>"; };
   		51F0EC9705C88DC700E6DF1B /* objc_utility.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; name = objc_utility.mm; path = bindings/objc/objc_utility.mm; sourceTree = "<group>"; };
  -		650B68D80639033F009D42DE /* protected_values.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = protected_values.cpp; sourceTree = "<group>"; };
  -		650B68D90639033F009D42DE /* protected_values.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = protected_values.h; sourceTree = "<group>"; };
   		651F6412039D5B5F0078395C /* dtoa.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = dtoa.cpp; sourceTree = "<group>"; };
   		651F6413039D5B5F0078395C /* dtoa.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = dtoa.h; sourceTree = "<group>"; };
   		652C107E08DA7B1E0020887D /* protected_reference.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = protected_reference.h; sourceTree = "<group>"; };
  @@ -338,6 +335,7 @@
   		6560A63D04B3B69F008AE952 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = /System/Library/Frameworks/CoreServices.framework; sourceTree = "<absolute>"; };
   		65621E6B089E859700760F35 /* property_slot.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = property_slot.cpp; sourceTree = "<group>"; };
   		65621E6C089E859700760F35 /* property_slot.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = property_slot.h; sourceTree = "<group>"; };
  +		657EEBBF094E445E008C9C7B /* HashCountedSet.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = HashCountedSet.h; sourceTree = "<group>"; };
   		6580F795094070560082C219 /* PassRefPtr.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PassRefPtr.h; sourceTree = "<group>"; };
   		65C02FBB0637462A003E7EE6 /* protect.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = protect.h; sourceTree = "<group>"; };
   		65C647B3093EF8D60022C380 /* RefPtr.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RefPtr.h; sourceTree = "<group>"; };
  @@ -532,9 +530,7 @@
   				65621E6B089E859700760F35 /* property_slot.cpp */,
   				65621E6C089E859700760F35 /* property_slot.h */,
   				938772E5038BFE19008635CE /* array_instance.h */,
  -				650B68D80639033F009D42DE /* protected_values.cpp */,
   				652C107E08DA7B1E0020887D /* protected_reference.h */,
  -				650B68D90639033F009D42DE /* protected_values.h */,
   				F692A84E0255597D01FF60F7 /* array_object.h */,
   				F692A84D0255597D01FF60F7 /* array_object.cpp */,
   				F692A8500255597D01FF60F7 /* bool_object.cpp */,
  @@ -664,6 +660,7 @@
   		65162EF108E6A21C007556CD /* kxmlcore */ = {
   			isa = PBXGroup;
   			children = (
  +				657EEBBF094E445E008C9C7B /* HashCountedSet.h */,
   				65C647B3093EF8D60022C380 /* RefPtr.h */,
   				6580F795094070560082C219 /* PassRefPtr.h */,
   				65D7D19B08F10B5B0015ABD8 /* FastMallocInternal.h */,
  @@ -822,7 +819,6 @@
   				932F5B840822A1C700736975 /* NP_jsobject.h in Headers */,
   				932F5B850822A1C700736975 /* npruntime.h in Headers */,
   				932F5B880822A1C700736975 /* protect.h in Headers */,
  -				932F5B890822A1C700736975 /* protected_values.h in Headers */,
   				932F5B8A0822A1C700736975 /* WebScriptObject.h in Headers */,
   				932F5B8B0822A1C700736975 /* WebScriptObjectPrivate.h in Headers */,
   				932F5B8C0822A1C700736975 /* npapi.h in Headers */,
  @@ -851,6 +847,7 @@
   				65EA4C9C092AF9E20093D800 /* JSLock.h in Headers */,
   				65C647B4093EF8D60022C380 /* RefPtr.h in Headers */,
   				6580F796094070560082C219 /* PassRefPtr.h in Headers */,
  +				657EEBC0094E445E008C9C7B /* HashCountedSet.h in Headers */,
   			);
   			runOnlyForDeploymentPostprocessing = 0;
   		};
  @@ -1213,7 +1210,6 @@
   				932F5BC90822A1C700736975 /* c_utility.cpp in Sources */,
   				932F5BCA0822A1C700736975 /* c_class.cpp in Sources */,
   				932F5BCB0822A1C700736975 /* npruntime.cpp in Sources */,
  -				932F5BCD0822A1C700736975 /* protected_values.cpp in Sources */,
   				932F5BCE0822A1C700736975 /* WebScriptObject.mm in Sources */,
   				932F5BCF0822A1C700736975 /* jni_objc.mm in Sources */,
   				932F5BD00822A1C700736975 /* softlinking.c in Sources */,
  
  
  
  1.54      +46 -29    JavaScriptCore/kjs/collector.cpp
  
  Index: collector.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/collector.cpp,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- collector.cpp	11 Dec 2005 02:05:42 -0000	1.53
  +++ collector.cpp	13 Dec 2005 11:06:04 -0000	1.54
  @@ -24,6 +24,7 @@
   
   #include <kxmlcore/FastMalloc.h>
   #include <kxmlcore/FastMallocInternal.h>
  +#include <kxmlcore/HashCountedSet.h>
   #include "internal.h"
   #include "list.h"
   #include "value.h"
  @@ -378,16 +379,44 @@
   #endif
   }
   
  +typedef HashCountedSet<JSCell *, PointerHash<JSCell *> > ProtectCounts;
  +
  +static ProtectCounts& protectedValues()
  +{
  +    static ProtectCounts pv;
  +    return pv;
  +}
  +
  +void Collector::protect(JSValue *k)
  +{
  +    assert(k);
  +    assert(JSLock::lockCount() > 0);
  +
  +    if (SimpleNumber::is(k))
  +      return;
  +
  +    protectedValues().insert(k->downcast());
  +}
  +
  +void Collector::unprotect(JSValue *k)
  +{
  +    assert(k);
  +    assert(JSLock::lockCount() > 0);
  +
  +    if (SimpleNumber::is(k))
  +      return;
  +
  +    protectedValues().remove(k->downcast());
  +}
  +
   void Collector::markProtectedObjects()
   {
  -  typedef ProtectedValues::KeyValue Entry;
  -  Entry *table = ProtectedValues::_table;
  -  Entry *end = table + ProtectedValues::_tableSize;
  -  for (Entry *entry = table; entry != end; ++entry) {
  -    JSCell *val = entry->key;
  -    if (val && !val->marked()) {
  +  ProtectCounts& pv = protectedValues();
  +  ProtectCounts::iterator end = pv.end();
  +  for (ProtectCounts::iterator it = pv.begin(); it != end; ++it) {
  +    JSCell *val = it->first;
  +    if (!val->marked())
         val->mark();
  -    }
     }
   }
   
  @@ -558,18 +587,7 @@
   
   size_t Collector::numReferencedObjects()
   {
  -  size_t count = 0;
  -
  -  size_t size = ProtectedValues::_tableSize;
  -  ProtectedValues::KeyValue *table = ProtectedValues::_table;
  -  for (size_t i = 0; i < size; i++) {
  -    JSCell *val = table[i].key;
  -    if (val) {
  -      ++count;
  -    }
  -  }
  -
  -  return count;
  +  return protectedValues().size();
   }
   
   #if APPLE_CHANGES
  @@ -606,19 +624,18 @@
   
   const void *Collector::rootObjectClasses()
   {
  +  // FIXME: this should be a HashSet (or maybe even CountedHashSet)
     CFMutableSetRef classes = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks);
   
  -  int size = ProtectedValues::_tableSize;
  -  ProtectedValues::KeyValue *table = ProtectedValues::_table;
  -  for (int i = 0; i < size; i++) {
  -    JSCell *val = table[i].key;
  -    if (val) {
  -      CFStringRef name = CFStringCreateWithCString(NULL, className(val), kCFStringEncodingASCII);
  -      CFSetAddValue(classes, name);
  -      CFRelease(name);
  -    }
  +  ProtectCounts& pv = protectedValues();
  +  ProtectCounts::iterator end = pv.end();
  +  for (ProtectCounts::iterator it = pv.begin(); it != end; ++it) {
  +    JSCell *val = it->first;
  +    CFStringRef name = CFStringCreateWithCString(NULL, className(val), kCFStringEncodingASCII);
  +    CFSetAddValue(classes, name);
  +    CFRelease(name);
     }
  -  
  +
     return classes;
   }
   
  
  
  
  1.21      +3 -0      JavaScriptCore/kjs/collector.h
  
  Index: collector.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/collector.h,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- collector.h	28 Sep 2005 02:25:49 -0000	1.20
  +++ collector.h	13 Dec 2005 11:06:04 -0000	1.21
  @@ -63,6 +63,9 @@
       static void finalCheck();
   #endif
   
  +    static void protect(JSValue *);
  +    static void unprotect(JSValue *);
  +
       static size_t numInterpreters();
       static size_t numGCNotAllowedObjects();
       static size_t numReferencedObjects();
  
  
  
  1.16      +5 -4      JavaScriptCore/kjs/protect.h
  
  Index: protect.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/protect.h,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- protect.h	11 Dec 2005 02:05:47 -0000	1.15
  +++ protect.h	13 Dec 2005 11:06:04 -0000	1.16
  @@ -26,19 +26,19 @@
   
   #include "reference.h"
   #include "value.h"
  -#include "protected_values.h"
  +#include "collector.h"
   #include "JSLock.h"
   
   namespace KJS {
   
       inline void gcProtect(JSValue *val) 
       { 
  -	ProtectedValues::increaseProtectCount(val);
  +	Collector::protect(val);
       }
   
       inline void gcUnprotect(JSValue *val)
       { 
  -	ProtectedValues::decreaseProtectCount(val);
  +	Collector::unprotect(val);
       }
   
       inline void gcProtectNullTolerant(JSValue *val) 
  @@ -51,7 +51,8 @@
   	if (val) gcUnprotect(val);
       }
       
  -    // FIXME: Share more code with RefPtr template? The only difference is the ref/deref operation.
  +    // FIXME: Share more code with RefPtr template? The only differences are the ref/deref operation
  +    // and the implicit conversion to raw pointer
       template <class T> class ProtectedPtr {
       public:
           ProtectedPtr() : m_ptr(NULL) { }
  
  
  
  1.40      +1 -1      JavaScriptCore/kjs/value.h
  
  Index: value.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/value.h,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- value.h	11 Dec 2005 02:05:49 -0000	1.39
  +++ value.h	13 Dec 2005 11:06:04 -0000	1.40
  @@ -67,7 +67,7 @@
    */
   class JSValue {
       friend class JSCell; // so it can derive from this class
  -    friend class ProtectedValues; // so it can call downcast()
  +    friend class Collector; // so it can call downcast()
   
   private:
       JSValue();
  
  
  
  1.2       +2 -0      JavaScriptCore/kxmlcore/HashFunctions.h
  
  Index: HashFunctions.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kxmlcore/HashFunctions.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HashFunctions.h	28 Sep 2005 22:01:17 -0000	1.1
  +++ HashFunctions.h	13 Dec 2005 11:06:05 -0000	1.2
  @@ -23,6 +23,8 @@
   #ifndef KXMLCORE_HASH_FUNCTIONS_H
   #define KXMLCORE_HASH_FUNCTIONS_H
   
  +#include <stdint.h>
  +
   namespace KXMLCore {
   
       template<typename T> class DefaultHash;
  
  
  
  1.2       +15 -1     JavaScriptCore/kxmlcore/HashMap.h
  
  Index: HashMap.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kxmlcore/HashMap.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HashMap.h	28 Sep 2005 22:01:17 -0000	1.1
  +++ HashMap.h	13 Dec 2005 11:06:05 -0000	1.2
  @@ -54,6 +54,7 @@
       int capacity() const;
       bool isEmpty() const;
   
  +    // iterators iterate over pairs of keys and values
       iterator begin();
       iterator end();
       const_iterator begin() const;
  @@ -65,8 +66,15 @@
       MappedType get(const KeyType &key) const;
   
       // replaces value but not key if key is already present
  +    // return value is a pair of the iterator to the key location, 
  +    // and a boolean that's true if a new value was actually added
       std::pair<iterator, bool> set(const KeyType &key, const MappedType &mapped); 
   
  +    // does nothing if key is already present
  +    // return value is a pair of the iterator to the key location, 
  +    // and a boolean that's true if a new value was actually added
  +    std::pair<iterator, bool> add(const KeyType &key, const MappedType &mapped); 
  +
       void remove(const KeyType& key);
       void remove(iterator it);
       void clear();
  @@ -139,7 +147,7 @@
   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));
  -    // the insert call aboveinsert won't change anything if the key is
  +    // the insert call above won't change anything if the key is
       // already there; in that case, make sure to set the value.
       if (!result.second)
           result.first->second = mapped;    
  @@ -147,6 +155,12 @@
   }
   
   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>::add(const KeyType &key, const MappedType &mapped)
  +{
  +    return m_impl.insert(ValueType(key, mapped));
  +}
  +
  +template<typename Key, typename Mapped, typename HashFunctions, typename KeyTraits, typename MappedTraits>
   inline Mapped HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::get(const KeyType &key) const
   {
       const_iterator it = find(key);
  
  
  
  1.2       +6 -0      JavaScriptCore/kxmlcore/HashMapPtrSpec.h
  
  Index: HashMapPtrSpec.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kxmlcore/HashMapPtrSpec.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HashMapPtrSpec.h	28 Sep 2005 22:01:17 -0000	1.1
  +++ HashMapPtrSpec.h	13 Dec 2005 11:06:05 -0000	1.2
  @@ -158,6 +158,9 @@
           
           std::pair<iterator, bool> set(const KeyType &key, const MappedType &mapped) 
           { return m_impl.set(key, mapped); }
  +
  +        std::pair<iterator, bool> add(const KeyType &key, const MappedType &mapped) 
  +        { return m_impl.add(key, mapped); }
           
           void remove(const KeyType& key) { m_impl.remove(key); }
           void remove(iterator it) { m_impl.remove(it.m_impl); }
  @@ -201,6 +204,9 @@
           
           std::pair<iterator, bool> set(const KeyType &key, const MappedType &mapped) 
           { return m_impl.set(key, mapped); }
  +
  +        std::pair<iterator, bool> add(const KeyType &key, const MappedType &mapped) 
  +        { return m_impl.add(key, mapped); }
           
           void remove(const KeyType& key) { m_impl.remove(key); }
           void remove(iterator it) { m_impl.remove(it.m_impl); }
  
  
  
  1.1                  JavaScriptCore/kxmlcore/HashCountedSet.h
  
  Index: HashCountedSet.h
  ===================================================================
  // -*- mode: c++; c-basic-offset: 4 -*-
  /*
   * This file is part of the KDE libraries
   * Copyright (C) 2005 Apple Computer, Inc.
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Library General Public
   * License as published by the Free Software Foundation; either
   * version 2 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Library General Public License for more details.
   *
   * You should have received a copy of the GNU Library General Public License
   * along with this library; see the file COPYING.LIB.  If not, write to
   * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   * Boston, MA 02111-1307, USA.
   *
   */
  
  #ifndef KXMLCORE_HASH_COUNTED_SET_H
  #define KXMLCORE_HASH_COUNTED_SET_H
  
  #include "Assertions.h"
  #include "HashMap.h"
  
  namespace KXMLCore {
  
      template<typename Value, typename HashFunctions = DefaultHash<Value>, typename Traits = HashTraits<Value> >
      class HashCountedSet {
      private:
          typedef HashMap<Value, unsigned, HashFunctions, Traits> ImplType;
      public:
          typedef Value ValueType;
          typedef typename ImplType::iterator iterator;
          typedef typename ImplType::const_iterator const_iterator;
          
          HashCountedSet() {}
          
          int size() const;
          int capacity() const;
          bool isEmpty() const;
          
          // iterators iterate over pairs of values and counts
          iterator begin();
          iterator end();
          const_iterator begin() const;
          const_iterator end() const;
          
          iterator find(const ValueType& value);
          const_iterator find(const ValueType& value) const;
          bool contains(const ValueType& value) const;
          unsigned count(const ValueType& value) const;
  
          // increases the count if an equal value is already present
          // returns value is a pair of an interator to the new value's location, 
          // and a bool that is true if an actual new insertion was done
          std::pair<iterator, bool> insert(const ValueType &value);
          
          // reduces the count of the value, and removes it if count
          // goes down to zero
          void remove(const ValueType& value);
          void remove(iterator it);
   
         void clear();
          
      private:
          ImplType m_impl;
      };
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline int HashCountedSet<Value, HashFunctions, Traits>::size() const
      {
          return m_impl.size(); 
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline int HashCountedSet<Value, HashFunctions, Traits>::capacity() const
      {
          return m_impl.capacity(); 
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline bool HashCountedSet<Value, HashFunctions, Traits>::isEmpty() const
      {
          return size() == 0; 
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline typename HashCountedSet<Value, HashFunctions, Traits>::iterator HashCountedSet<Value, HashFunctions, Traits>::begin()
      {
          return m_impl.begin(); 
      }
  
      template<typename Value, typename HashFunctions, typename Traits>
      inline typename HashCountedSet<Value, HashFunctions, Traits>::iterator HashCountedSet<Value, HashFunctions, Traits>::end()
      {
          return m_impl.end(); 
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline typename HashCountedSet<Value, HashFunctions, Traits>::const_iterator HashCountedSet<Value, HashFunctions, Traits>::begin() const
      {
          return m_impl.begin(); 
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline typename HashCountedSet<Value, HashFunctions, Traits>::const_iterator HashCountedSet<Value, HashFunctions, Traits>::end() const
      {
          return m_impl.end(); 
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline typename HashCountedSet<Value, HashFunctions, Traits>::iterator HashCountedSet<Value, HashFunctions, Traits>::find(const ValueType& value)
      {
          return m_impl.find(value); 
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline typename HashCountedSet<Value, HashFunctions, Traits>::const_iterator HashCountedSet<Value, HashFunctions, Traits>::find(const ValueType& value) const
      {
          return m_impl.find(value); 
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline bool HashCountedSet<Value, HashFunctions, Traits>::contains(const ValueType& value) const
      {
          return m_impl.contains(value); 
      }
  
      template<typename Value, typename HashFunctions, typename Traits>
      inline unsigned HashCountedSet<Value, HashFunctions, Traits>::count(const ValueType& value) const
      {
          return m_impl.get(value);
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline std::pair<typename HashCountedSet<Value, HashFunctions, Traits>::iterator, bool> HashCountedSet<Value, HashFunctions, Traits>::insert(const ValueType &value)
      {
          pair<iterator, bool> result = m_impl.add(value, 0); 
          ++result.first->second;
          return result;
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline void HashCountedSet<Value, HashFunctions, Traits>::remove(const ValueType& value)
      {
          remove(find(value));
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline void HashCountedSet<Value, HashFunctions, Traits>::remove(iterator it)
      {
          if (it == end())
              return;
  
          unsigned oldVal = it->second;
          ASSERT(oldVal != 0);
          unsigned newVal = oldVal - 1;
          if (newVal == 0)
              m_impl.remove(it);
          else
              it->second = newVal;
      }
      
      template<typename Value, typename HashFunctions, typename Traits>
      inline void HashCountedSet<Value, HashFunctions, Traits>::clear()
      {
          m_impl.clear(); 
      }
  
  } // namespace khtml
  
  using KXMLCore::HashCountedSet;
  
  #endif /* KXMLCORE_HASH_COUNTED_SET_H */
  
  
  
  
  
  1.519     +10 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.518
  retrieving revision 1.519
  diff -u -r1.518 -r1.519
  --- ChangeLog	13 Dec 2005 01:50:22 -0000	1.518
  +++ ChangeLog	13 Dec 2005 11:06:06 -0000	1.519
  @@ -1,3 +1,13 @@
  +2005-12-13  Maciej Stachowiak  <mjs at apple.com>
  +
  +        Reviewed by Eric.
  +
  +        - updated for new HashCountedSet class
  +
  +        * ForwardingHeaders/kxmlcore/HashCountedSet.h: Added forwarding header.
  +        * khtml/ecma/kjs_binding.cpp: Moved #define to disable pointer specialization higher
  +	in the file.
  +
   2005-12-12  Justin Garcia  <justin.garcia at apple.com>
   
           Reviewed by harrison
  
  
  
  1.1                  WebCore/ForwardingHeaders/kxmlcore/HashCountedSet.h
  
  Index: HashCountedSet.h
  ===================================================================
  #import <JavaScriptCore/HashCountedSet.h>
  
  
  
  1.51      +5 -6      WebCore/khtml/ecma/kjs_binding.cpp
  
  Index: kjs_binding.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/ecma/kjs_binding.cpp,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- kjs_binding.cpp	11 Dec 2005 02:06:04 -0000	1.50
  +++ kjs_binding.cpp	13 Dec 2005 11:06:10 -0000	1.51
  @@ -18,6 +18,11 @@
    *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
   
  +// gcc 3.x can't handle including the HashMap pointer specialization in this file
  +#ifndef __GLIBCXX__ // less than gcc 3.4
  +#define HASH_MAP_PTR_SPEC_WORKAROUND 1
  +#endif
  +
   #include "config.h"
   #include "kjs_binding.h"
   
  @@ -34,12 +39,6 @@
   #include "xml/EventNames.h"
   #include "dom/css_stylesheet.h"
   
  -// gcc 3.x can't handle including the HashMap pointer specialization in this file
  -#ifndef __GLIBCXX__ // less than gcc 3.4
  -#define HASH_MAP_PTR_SPEC_WORKAROUND 1
  -#endif
  -#include <kxmlcore/HashMap.h>
  -
   #include <kdebug.h>
   
   using namespace DOM::EventNames;
  
  
  



More information about the webkit-changes mailing list