Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8ValueCache.h

Issue 1389383003: WIP: Introduce CompressibleString Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase onto crrev.com/1564773002 Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5f202e5120c5ab7b48ec78b6514d154bb497c1cc 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.h
+++ b/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.h
@@ -33,6 +33,7 @@
#include "wtf/Noncopyable.h"
#include "wtf/RefPtr.h"
#include "wtf/text/AtomicString.h"
+#include "wtf/text/CompressibleString.h"
#include "wtf/text/WTFString.h"
#include <v8.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.
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());
+ 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.

Powered by Google App Engine
This is Rietveld 408576698