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>
Reviewed by Simon Fraser.
......
......@@ -27,6 +27,7 @@
package CodeGeneratorV8;
use File::stat;
use Digest::MD5;
my $module = "";
my $outputDir = "";
......@@ -593,7 +594,10 @@ END
}
} else {
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");
} else {
my $wrapper = GenerateSVGStaticPodTypeWrapper($returnType, $getterString);
......
......@@ -30,11 +30,14 @@
#if ENABLE(SVG)
#include <utility>
#include "SVGElement.h"
#include "SVGList.h"
#include "V8Proxy.h"
#include <wtf/Assertions.h>
#include <wtf/HashFunctions.h>
#include <wtf/HashMap.h>
#include <wtf/RefCounted.h>
#include <wtf/StdLibExtras.h>
......@@ -251,6 +254,7 @@ struct PODTypeWrapperCacheInfo {
: creator(0)
, getter(0)
, setter(0)
, fieldHash(0)
{ }
// Deleted value
......@@ -258,6 +262,7 @@ struct PODTypeWrapperCacheInfo {
: creator(reinterpret_cast<PODTypeCreator*>(-1))
, getter(0)
, setter(0)
, fieldHash(0)
{
}
......@@ -266,10 +271,11 @@ struct PODTypeWrapperCacheInfo {
return creator == reinterpret_cast<PODTypeCreator*>(-1);
}
PODTypeWrapperCacheInfo(PODTypeCreator* _creator, GetterMethod _getter, SetterMethod _setter)
PODTypeWrapperCacheInfo(PODTypeCreator* _creator, GetterMethod _getter, SetterMethod _setter, unsigned _fieldHash)
: creator(_creator)
, getter(_getter)
, setter(_setter)
, fieldHash(_fieldHash)
{
ASSERT(creator);
ASSERT(getter);
......@@ -277,22 +283,23 @@ struct PODTypeWrapperCacheInfo {
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;
GetterMethod getter;
SetterMethod setter;
unsigned fieldHash;
};
template<typename PODType, typename PODTypeCreator>
struct PODTypeWrapperCacheInfoHash {
static unsigned hash(const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& info)
{
unsigned creator = reinterpret_cast<unsigned>(info.creator);
unsigned getter = reinterpret_cast<unsigned>(*(void**)&info.getter);
unsigned setter = reinterpret_cast<unsigned>(*(void**)&info.setter);
return (creator * 13) + getter ^ (setter >> 2);
// We can't hash member function pointers, but we have enough material
// to hash the pointer and field identifier, and on a collision
// operator== will still differentiate the member function pointers.
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)
......@@ -350,10 +357,10 @@ public:
}
// 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());
CacheInfo info(creator, getter, setter);
CacheInfo info(creator, getter, setter, fieldHash);
if (map.contains(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