Commit 22bf6875 authored by dglazkov@chromium.org's avatar dglazkov@chromium.org

2009-07-30 Dean McNamee <deanm@chromium.org>

        Reviewed by Dimitri Glazkov.

        Don't try to hash member function pointers, instead use a precomputed value based on the field.
        https://bugs.webkit.org/show_bug.cgi?id=27843

        * bindings/scripts/CodeGeneratorV8.pm:
        * bindings/v8/V8SVGPODTypeWrapper.h:
        (WebCore::PODTypeWrapperCacheInfo::PODTypeWrapperCacheInfo):
        (WebCore::PODTypeWrapperCacheInfo::operator==):
        (WebCore::PODTypeWrapperCacheInfoHash::hash):
        (WebCore::V8SVGDynamicPODTypeWrapperCache::lookupOrCreateWrapper):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@46596 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c3eeea51
2009-07-30 Dean McNamee <deanm@chromium.org>
Reviewed by Dimitri Glazkov.
Don't try to hash member function pointers, instead use a precomputed value based on the field.
https://bugs.webkit.org/show_bug.cgi?id=27843
* bindings/scripts/CodeGeneratorV8.pm:
* bindings/v8/V8SVGPODTypeWrapper.h:
(WebCore::PODTypeWrapperCacheInfo::PODTypeWrapperCacheInfo):
(WebCore::PODTypeWrapperCacheInfo::operator==):
(WebCore::PODTypeWrapperCacheInfoHash::hash):
(WebCore::V8SVGDynamicPODTypeWrapperCache::lookupOrCreateWrapper):
2009-07-30 Xan Lopez <xlopez@igalia.com> 2009-07-30 Xan Lopez <xlopez@igalia.com>
Reviewed by Simon Fraser. Reviewed by Simon Fraser.
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
package CodeGeneratorV8; package CodeGeneratorV8;
use File::stat; use File::stat;
use Digest::MD5;
my $module = ""; my $module = "";
my $outputDir = ""; my $outputDir = "";
...@@ -593,7 +594,10 @@ END ...@@ -593,7 +594,10 @@ END
} }
} else { } else {
if ($implClassIsAnimatedType) { if ($implClassIsAnimatedType) {
my $wrapper = "V8SVGDynamicPODTypeWrapperCache<$nativeType, $implClassName>::lookupOrCreateWrapper(imp, &${implClassName}::$getter, &${implClassName}::$setter)"; # We can't hash member function pointers, so instead generate
# some hashing material based on the names of the methods.
my $hashhex = substr(Digest::MD5::md5_hex("${implClassName}::$getter ${implClassName}::$setter)"), 0, 8);
my $wrapper = "V8SVGDynamicPODTypeWrapperCache<$nativeType, $implClassName>::lookupOrCreateWrapper(imp, &${implClassName}::$getter, &${implClassName}::$setter, 0x$hashhex)";
push(@implContentDecls, " RefPtr<V8SVGPODTypeWrapper<" . $nativeType . "> > wrapper = $wrapper;\n"); push(@implContentDecls, " RefPtr<V8SVGPODTypeWrapper<" . $nativeType . "> > wrapper = $wrapper;\n");
} else { } else {
my $wrapper = GenerateSVGStaticPodTypeWrapper($returnType, $getterString); my $wrapper = GenerateSVGStaticPodTypeWrapper($returnType, $getterString);
......
...@@ -30,11 +30,14 @@ ...@@ -30,11 +30,14 @@
#if ENABLE(SVG) #if ENABLE(SVG)
#include <utility>
#include "SVGElement.h" #include "SVGElement.h"
#include "SVGList.h" #include "SVGList.h"
#include "V8Proxy.h" #include "V8Proxy.h"
#include <wtf/Assertions.h> #include <wtf/Assertions.h>
#include <wtf/HashFunctions.h>
#include <wtf/HashMap.h> #include <wtf/HashMap.h>
#include <wtf/RefCounted.h> #include <wtf/RefCounted.h>
#include <wtf/StdLibExtras.h> #include <wtf/StdLibExtras.h>
...@@ -251,6 +254,7 @@ struct PODTypeWrapperCacheInfo { ...@@ -251,6 +254,7 @@ struct PODTypeWrapperCacheInfo {
: creator(0) : creator(0)
, getter(0) , getter(0)
, setter(0) , setter(0)
, fieldHash(0)
{ } { }
// Deleted value // Deleted value
...@@ -258,6 +262,7 @@ struct PODTypeWrapperCacheInfo { ...@@ -258,6 +262,7 @@ struct PODTypeWrapperCacheInfo {
: creator(reinterpret_cast<PODTypeCreator*>(-1)) : creator(reinterpret_cast<PODTypeCreator*>(-1))
, getter(0) , getter(0)
, setter(0) , setter(0)
, fieldHash(0)
{ {
} }
...@@ -266,10 +271,11 @@ struct PODTypeWrapperCacheInfo { ...@@ -266,10 +271,11 @@ struct PODTypeWrapperCacheInfo {
return creator == reinterpret_cast<PODTypeCreator*>(-1); return creator == reinterpret_cast<PODTypeCreator*>(-1);
} }
PODTypeWrapperCacheInfo(PODTypeCreator* _creator, GetterMethod _getter, SetterMethod _setter) PODTypeWrapperCacheInfo(PODTypeCreator* _creator, GetterMethod _getter, SetterMethod _setter, unsigned _fieldHash)
: creator(_creator) : creator(_creator)
, getter(_getter) , getter(_getter)
, setter(_setter) , setter(_setter)
, fieldHash(_fieldHash)
{ {
ASSERT(creator); ASSERT(creator);
ASSERT(getter); ASSERT(getter);
...@@ -277,22 +283,23 @@ struct PODTypeWrapperCacheInfo { ...@@ -277,22 +283,23 @@ struct PODTypeWrapperCacheInfo {
bool operator==(const PODTypeWrapperCacheInfo& other) const bool operator==(const PODTypeWrapperCacheInfo& other) const
{ {
return creator == other.creator && getter == other.getter && setter == other.setter; return creator == other.creator && fieldHash == other.fieldHash && getter == other.getter && setter == other.setter;
} }
PODTypeCreator* creator; PODTypeCreator* creator;
GetterMethod getter; GetterMethod getter;
SetterMethod setter; SetterMethod setter;
unsigned fieldHash;
}; };
template<typename PODType, typename PODTypeCreator> template<typename PODType, typename PODTypeCreator>
struct PODTypeWrapperCacheInfoHash { struct PODTypeWrapperCacheInfoHash {
static unsigned hash(const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& info) static unsigned hash(const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& info)
{ {
unsigned creator = reinterpret_cast<unsigned>(info.creator); // We can't hash member function pointers, but we have enough material
unsigned getter = reinterpret_cast<unsigned>(*(void**)&info.getter); // to hash the pointer and field identifier, and on a collision
unsigned setter = reinterpret_cast<unsigned>(*(void**)&info.setter); // operator== will still differentiate the member function pointers.
return (creator * 13) + getter ^ (setter >> 2); return WTF::PairHash<void*, unsigned>::hash(std::pair<void*, unsigned>(info.creator, info.fieldHash));
} }
static bool equal(const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& a, const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& b) static bool equal(const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& a, const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& b)
...@@ -350,10 +357,10 @@ public: ...@@ -350,10 +357,10 @@ public:
} }
// Used for readwrite attributes only // Used for readwrite attributes only
static PassRefPtr<WrapperBase> lookupOrCreateWrapper(PODTypeCreator* creator, GetterMethod getter, SetterMethod setter) static PassRefPtr<WrapperBase> lookupOrCreateWrapper(PODTypeCreator* creator, GetterMethod getter, SetterMethod setter, unsigned fieldHash)
{ {
DynamicWrapperHashMap& map(dynamicWrapperHashMap()); DynamicWrapperHashMap& map(dynamicWrapperHashMap());
CacheInfo info(creator, getter, setter); CacheInfo info(creator, getter, setter, fieldHash);
if (map.contains(info)) if (map.contains(info))
return map.get(info); return map.get(info);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment