Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/V8ValueCache.h |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.h b/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.h |
| index 3bc2e00a289657813f6d9724aad46ce8651f8fc3..d7f26a6bf3718bb51aaaa4505f152dcf44a98bd6 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.h |
| +++ b/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.h |
| @@ -28,6 +28,7 @@ |
| #include "bindings/core/v8/V8GlobalValueMap.h" |
| #include "core/CoreExport.h" |
| +#include "platform/text/CompressibleString.h" |
| #include "wtf/Allocator.h" |
| #include "wtf/HashMap.h" |
| #include "wtf/Noncopyable.h" |
| @@ -64,21 +65,57 @@ public: |
| static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>&); |
| }; |
| +class CompressibleStringCacheMapTraits : public V8GlobalValueMapTraits<CompressibleStringImpl*, v8::String, v8::kWeakWithParameter> { |
| + STATIC_ONLY(CompressibleStringCacheMapTraits); |
| +public: |
| + // Weak traits: |
| + typedef CompressibleStringImpl WeakCallbackDataType; |
| + typedef v8::GlobalValueMap<CompressibleStringImpl*, v8::String, CompressibleStringCacheMapTraits> MapType; |
| + |
| + static WeakCallbackDataType* WeakCallbackParameter( |
| + MapType* map, CompressibleStringImpl* key, v8::Local<v8::String>& value) { return key; } |
| + static void DisposeCallbackData(WeakCallbackDataType* callbackData) { } |
| + |
| + static MapType* MapFromWeakCallbackInfo( |
| + const v8::WeakCallbackInfo<WeakCallbackDataType>&); |
| + |
| + static CompressibleStringImpl* KeyFromWeakCallbackInfo( |
| + const v8::WeakCallbackInfo<WeakCallbackDataType>& data) |
| + { |
| + return data.GetParameter(); |
| + } |
| + |
| + static void OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataType>&); |
| + |
| + static void Dispose(v8::Isolate*, v8::Global<v8::String> value, CompressibleStringImpl* key); |
| + static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>&); |
| +}; |
| class CORE_EXPORT StringCache { |
| USING_FAST_MALLOC(StringCache); |
| WTF_MAKE_NONCOPYABLE(StringCache); |
| public: |
| - explicit StringCache(v8::Isolate* isolate) : m_stringCache(isolate) { } |
| + explicit StringCache(v8::Isolate* isolate) |
| + : m_stringCache(isolate) |
| + , m_compressibleStringCache(isolate) |
| + { |
| + } |
| v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, StringImpl* stringImpl) |
| { |
| + // Note that the last CompressibleString is not cached. |
|
haraken
2016/01/15 12:46:21
This comment should be moved to the below v8Extern
hajimehoshi
2016/01/18 09:42:26
Done.
|
| ASSERT(stringImpl); |
| if (m_lastStringImpl.get() == stringImpl) |
| return m_lastV8String.NewLocal(isolate); |
| return v8ExternalStringSlow(isolate, stringImpl); |
| } |
| + v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, const CompressibleString& string) |
| + { |
| + ASSERT(!string.isNull()); |
|
haraken
2016/01/15 12:46:21
Add:
ASSERT(m_lastStringImpl.get() != string.im
hajimehoshi
2016/01/18 09:42:26
string.impl() is CompressibleStringImpl* and I thi
|
| + return v8ExternalStringSlow(isolate, string); |
| + } |
| + |
| void setReturnValueFromString(v8::ReturnValue<v8::Value> returnValue, StringImpl* stringImpl) |
| { |
| ASSERT(stringImpl); |
| @@ -91,16 +128,21 @@ public: |
| void dispose(); |
| friend class StringCacheMapTraits; |
| + friend class CompressibleStringCacheMapTraits; |
| private: |
| v8::Local<v8::String> v8ExternalStringSlow(v8::Isolate*, StringImpl*); |
| + v8::Local<v8::String> v8ExternalStringSlow(v8::Isolate*, const CompressibleString&); |
| void setReturnValueFromStringSlow(v8::ReturnValue<v8::Value>, StringImpl*); |
| v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, StringImpl*); |
| + v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, const CompressibleString&); |
| void InvalidateLastString(); |
| StringCacheMapTraits::MapType m_stringCache; |
| StringCacheMapTraits::MapType::PersistentValueReference m_lastV8String; |
| + CompressibleStringCacheMapTraits::MapType m_compressibleStringCache; |
| + |
| // Note: RefPtr is a must as we cache by StringImpl* equality, not identity |
| // hence lastStringImpl might be not a key of the cache (in sense of identity) |
| // and hence it's not refed on addition. |