Index: third_party/WebKit/Source/bindings/core/v8/V8StringResource.h |
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8StringResource.h b/third_party/WebKit/Source/bindings/core/v8/V8StringResource.h |
index 83316f8f6e49a5432c9895c4287c5c0264872e83..c3f0e0f5ab3e7ce76daae6f62d2fd134cbcae45f 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/V8StringResource.h |
+++ b/third_party/WebKit/Source/bindings/core/v8/V8StringResource.h |
@@ -28,6 +28,7 @@ |
#include "bindings/core/v8/ExceptionState.h" |
#include "core/CoreExport.h" |
+#include "platform/text/CompressableString.h" |
#include "wtf/Allocator.h" |
#include "wtf/Threading.h" |
#include "wtf/text/AtomicString.h" |
@@ -62,24 +63,54 @@ public: |
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(memoryConsumption(string)); |
} |
+ explicit WebCoreStringResourceBase(const CompressableString& string) |
+ : m_compressableString(string) |
+ { |
+#if ENABLE(ASSERT) |
+ m_threadId = WTF::currentThread(); |
+#endif |
+ ASSERT(!string.isNull()); |
+ v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(memoryConsumption(string)); |
+ } |
+ |
virtual ~WebCoreStringResourceBase() |
{ |
#if ENABLE(ASSERT) |
ASSERT(m_threadId == WTF::currentThread()); |
#endif |
- int reducedExternalMemory = -memoryConsumption(m_plainString); |
- if (m_plainString.impl() != m_atomicString.impl() && !m_atomicString.isNull()) |
- reducedExternalMemory -= memoryConsumption(m_atomicString.string()); |
+ int reducedExternalMemory = 0; |
+ if (LIKELY(m_compressableString.isNull())) { |
+ reducedExternalMemory = -memoryConsumption(m_plainString); |
+ if (m_plainString.impl() != m_atomicString.impl() && !m_atomicString.isNull()) |
+ reducedExternalMemory -= memoryConsumption(m_atomicString.string()); |
+ } else { |
+ reducedExternalMemory = -memoryConsumption(m_compressableString); |
+ } |
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(reducedExternalMemory); |
+ |
+ // FIX this! |
} |
- const String& webcoreString() { return m_plainString; } |
+ String webcoreString() |
+ { |
+ if (!m_compressableString.isNull()) { |
+ ASSERT(m_plainString.isNull()); |
+ ASSERT(m_atomicString.isNull()); |
+ return m_compressableString.toString(); |
+ } |
+ return m_plainString; |
+ } |
- const AtomicString& atomicString() |
+ AtomicString atomicString() |
{ |
#if ENABLE(ASSERT) |
ASSERT(m_threadId == WTF::currentThread()); |
#endif |
+ if (!m_compressableString.isNull()) { |
+ ASSERT(m_plainString.isNull()); |
+ ASSERT(m_atomicString.isNull()); |
+ return AtomicString(m_compressableString.toString()); |
+ } |
if (m_atomicString.isNull()) { |
m_atomicString = AtomicString(m_plainString); |
ASSERT(!m_atomicString.isNull()); |
@@ -89,6 +120,8 @@ public: |
return m_atomicString; |
} |
+ const CompressableString& compressableString() { return m_compressableString; } |
+ |
protected: |
// A shallow copy of the string. Keeps the string buffer alive until the V8 engine garbage collects it. |
String m_plainString; |
@@ -99,11 +132,21 @@ protected: |
// into that string. |
AtomicString m_atomicString; |
+ CompressableString m_compressableString; |
+ |
private: |
static int memoryConsumption(const String& string) |
{ |
return string.length() * (string.is8Bit() ? sizeof(LChar) : sizeof(UChar)); |
} |
+ |
+ // TODO(hajimehoshi): This returns the size of |string| not compressed so |
+ // far. Is this really OK? |
+ static int memoryConsumption(const CompressableString& string) |
+ { |
+ return string.sizeInBytes(); |
+ } |
+ |
#if ENABLE(ASSERT) |
WTF::ThreadIdentifier m_threadId; |
#endif |
@@ -153,6 +196,51 @@ public: |
} |
}; |
+class WebCoreCompressableStringResource16 final : public WebCoreStringResourceBase, public v8::String::ExternalStringResource { |
+ WTF_MAKE_NONCOPYABLE(WebCoreCompressableStringResource16); |
+public: |
+ explicit WebCoreCompressableStringResource16(const CompressableString& string) |
+ : WebCoreStringResourceBase(string) |
+ { |
+ // ASSERT(m_string); |
+ ASSERT(!m_compressableString.is8Bit()); |
+ } |
+ |
+ bool isCompressable() override { return true; } |
+ |
+ size_t length() const override |
+ { |
+ return m_compressableString.length(); |
+ } |
+ |
+ const uint16_t* data() const override |
+ { |
+ return reinterpret_cast<const uint16_t*>(m_compressableString.characters16()); |
+ } |
+}; |
+ |
+class WebCoreCompressableStringResource8 final : public WebCoreStringResourceBase, public v8::String::ExternalOneByteStringResource { |
+ WTF_MAKE_NONCOPYABLE(WebCoreCompressableStringResource8); |
+public: |
+ explicit WebCoreCompressableStringResource8(const CompressableString& string) |
+ : WebCoreStringResourceBase(string) |
+ { |
+ ASSERT(m_compressableString.is8Bit()); |
+ } |
+ |
+ bool isCompressable() override { return true; } |
+ |
+ size_t length() const override |
+ { |
+ return m_compressableString.length(); |
+ } |
+ |
+ const char* data() const override |
+ { |
+ return reinterpret_cast<const char*>(m_compressableString.characters8()); |
+ } |
+}; |
+ |
enum ExternalMode { |
Externalize, |
DoNotExternalize |
@@ -162,6 +250,9 @@ template <typename StringType> |
CORE_EXPORT StringType v8StringToWebCoreString(v8::Local<v8::String>, ExternalMode); |
CORE_EXPORT String int32ToWebCoreString(int value); |
+template <typename StringType> |
+CORE_EXPORT StringType v8StringToWebCoreString2(v8::Local<v8::String>, ExternalMode); |
+ |
// V8StringResource is an adapter class that converts V8 values to Strings |
// or AtomicStrings as appropriate, using multiple typecast operators. |
enum V8StringResourceMode { |