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

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

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.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp b/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp
index 9c902c2811dcd4401d5d6e5cb19832f297d71a21..91531024478fa1549de69027279823cb7ddf165f 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp
@@ -54,6 +54,29 @@ void StringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbac
V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastString();
}
+
+CompressibleStringCacheMapTraits::MapType* CompressibleStringCacheMapTraits::MapFromWeakCallbackInfo(
+ const v8::WeakCallbackInfo<WeakCallbackDataType>& data)
+{
+ return &(V8PerIsolateData::from(data.GetIsolate())->stringCache()->m_compressibleStringCache);
+}
+
+void CompressibleStringCacheMapTraits::Dispose(
+ v8::Isolate* isolate, v8::Global<v8::String> value, CompressibleStringImpl* key)
+{
+ key->deref();
+}
+
+void CompressibleStringCacheMapTraits::DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>& data)
+{
+ data.GetParameter()->deref();
+}
+
+void CompressibleStringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataType>& data)
+{
+}
+
+
void StringCache::dispose()
{
// The MapType::Dispose callback calls StringCache::InvalidateLastString,
@@ -83,6 +106,27 @@ static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Stri
return newString;
}
+static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const CompressibleString& string)
+{
+ if (string.is8Bit()) {
+ WebCoreCompressibleStringResource8* stringResource = new WebCoreCompressibleStringResource8(string);
+ v8::Local<v8::String> newString;
+ if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&newString)) {
+ delete stringResource;
+ return v8::String::Empty(isolate);
+ }
+ return newString;
+ }
+
+ WebCoreCompressibleStringResource16* stringResource = new WebCoreCompressibleStringResource16(string);
+ v8::Local<v8::String> newString;
+ if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newString)) {
+ delete stringResource;
+ return v8::String::Empty(isolate);
+ }
+ return newString;
+}
+
v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, StringImpl* stringImpl)
{
if (!stringImpl->length())
@@ -98,6 +142,14 @@ v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, St
return createStringAndInsertIntoCache(isolate, stringImpl);
}
+v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, const CompressibleString& string)
+{
+ if (!string.length())
+ return v8::String::Empty(isolate);
+
+ return createStringAndInsertIntoCache(isolate, string);
+}
+
void StringCache::setReturnValueFromStringSlow(v8::ReturnValue<v8::Value> returnValue, StringImpl* stringImpl)
{
if (!stringImpl->length()) {
@@ -135,6 +187,27 @@ v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i
return newString;
}
+v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* isolate, const CompressibleString& string)
+{
+ CompressibleStringImpl* stringImpl = string.impl().get();
+
+ ASSERT(!m_compressibleStringCache.Contains(stringImpl));
+ ASSERT(stringImpl->originalLength());
+
+ v8::Local<v8::String> newString = makeExternalString(isolate, string);
+ ASSERT(!newString.IsEmpty());
+ ASSERT(newString->Length());
+
+ v8::UniquePersistent<v8::String> wrapper(isolate, newString);
+
+ stringImpl->ref();
+ wrapper.MarkIndependent();
+ CompressibleStringCacheMapTraits::MapType::PersistentValueReference unused;
+ m_compressibleStringCache.Set(stringImpl, wrapper.Pass(), &unused);
+
+ return newString;
+}
+
void StringCache::InvalidateLastString()
{
m_lastStringImpl = nullptr;

Powered by Google App Engine
This is Rietveld 408576698