| Index: third_party/WebKit/Source/platform/text/CompressibleString.cpp
|
| diff --git a/third_party/WebKit/Source/platform/text/CompressibleString.cpp b/third_party/WebKit/Source/platform/text/CompressibleString.cpp
|
| index 38e6c09f41e1978f53a41ac1f73072b8307fd3ce..c40e344a4d7d3834ea88cd25ebdb5671b4c0f758 100644
|
| --- a/third_party/WebKit/Source/platform/text/CompressibleString.cpp
|
| +++ b/third_party/WebKit/Source/platform/text/CompressibleString.cpp
|
| @@ -5,6 +5,7 @@
|
| #include "platform/text/CompressibleString.h"
|
|
|
| #include "public/platform/Platform.h"
|
| +#include "third_party/zlib/google/compression_utils.h"
|
| #include "wtf/Assertions.h"
|
| #include "wtf/WTFThreadData.h"
|
| #include "wtf/text/WTFString.h"
|
| @@ -77,7 +78,9 @@ void CompressibleStringImpl::compressAll()
|
|
|
| CompressibleStringImpl::CompressibleStringImpl(PassRefPtr<StringImpl> impl)
|
| : m_string(impl)
|
| - , m_isCompressed(false)
|
| + , m_originalLength(m_string.length())
|
| + , m_compressedData(nullptr)
|
| + , m_compressedDataSize(0)
|
| {
|
| if (originalContentSizeInBytes() > CompressibleStringImplSizeThrehold)
|
| compressibleStringTable().add(this);
|
| @@ -100,17 +103,30 @@ static void recordCompressibleStringCount(CompressibleStringCountType type)
|
| Platform::current()->histogramEnumeration("Memory.CompressibleStringCount", type, CompressibleStringCountTypeMax + 1);
|
| }
|
|
|
| -// compressString does nothing but collect UMA so far.
|
| -// TODO(hajimehoshi): Implement this.
|
| void CompressibleStringImpl::compressString()
|
| {
|
| recordCompressibleStringCount(StringWasCompressedInBackgroundTab);
|
| ASSERT(!isCompressed());
|
| - m_isCompressed = true;
|
| + ASSERT(!m_compressedData);
|
| + ASSERT(!m_compressedDataSize);
|
| +
|
| + // TODO(hajimehoshi): Now components offers funcitons accepting only
|
| + // std::strings. This is not efficient. We should offer char* version.
|
| + std::string in, out;
|
| + if (m_string.is8Bit()) {
|
| + in = std::string(reinterpret_cast<const char*>(m_string.characters8()), originalContentSizeInBytes());
|
| + m_string = emptyString();
|
| + } else {
|
| + in = std::string(reinterpret_cast<const char*>(m_string.characters16()), originalContentSizeInBytes());
|
| + m_string = emptyString16Bit();
|
| + }
|
| + compression::GzipCompress(in, &out);
|
| +
|
| + m_compressedData = WTF::Partitions::fastMalloc(out.size(), "CompressibleString");
|
| + memcpy(m_compressedData, out.c_str(), out.size());
|
| + m_compressedDataSize = out.size();
|
| }
|
|
|
| -// decompressString does nothing but collect UMA so far.
|
| -// TODO(hajimehoshi): Implement this.
|
| void CompressibleStringImpl::decompressString()
|
| {
|
| // TODO(hajimehoshi): We wanted to tell whether decompressing in a
|
| @@ -122,7 +138,27 @@ void CompressibleStringImpl::decompressString()
|
| // changes.
|
| recordCompressibleStringCount(StringWasDecompressed);
|
| ASSERT(isCompressed());
|
| - m_isCompressed = false;
|
| + ASSERT(m_compressedData);
|
| + ASSERT(m_compressedDataSize);
|
| +
|
| + std::string in(static_cast<const char*>(m_compressedData), m_compressedDataSize);
|
| + std::string out;
|
| + compression::GzipUncompress(in, &out);
|
| +
|
| + if (is8Bit()) {
|
| + LChar* data = nullptr;
|
| + m_string = StringImpl::createUninitialized(out.size() / sizeof(LChar), data);
|
| + memcpy(data, out.c_str(), out.size());
|
| + } else {
|
| + UChar* data = nullptr;
|
| + m_string = StringImpl::createUninitialized(out.size() / sizeof(UChar), data);
|
| + memcpy(data, out.c_str(), out.size());
|
| + }
|
| +
|
| + WTF::Partitions::fastFree(m_compressedData);
|
| + m_compressedData = nullptr;
|
| + m_compressedDataSize = 0;
|
| + ASSERT(m_originalLength == m_string.length());
|
| }
|
|
|
| } // namespace blink
|
|
|