| 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 3b7f6c394ca847483967aeea680b931481344c80..0f47d1ba8a321870110aef1455077c583ecc5e11 100644
|
| --- a/third_party/WebKit/Source/platform/text/CompressibleString.cpp
|
| +++ b/third_party/WebKit/Source/platform/text/CompressibleString.cpp
|
| @@ -5,6 +5,8 @@
|
| #include "platform/text/CompressibleString.h"
|
|
|
| #include "platform/Histogram.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"
|
| @@ -23,7 +25,7 @@ public:
|
|
|
| void add(CompressibleStringImpl* string)
|
| {
|
| - ASSERT(!m_table.contains(string));
|
| + DCHECK(!m_table.contains(string));
|
| m_table.add(string);
|
| }
|
|
|
| @@ -34,7 +36,7 @@ public:
|
|
|
| void remove(CompressibleStringImpl* string)
|
| {
|
| - ASSERT(m_table.contains(string));
|
| + DCHECK(m_table.contains(string));
|
| m_table.remove(string);
|
| }
|
|
|
| @@ -77,7 +79,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);
|
| @@ -101,17 +105,30 @@ static void recordCompressibleStringCount(CompressibleStringCountType type)
|
| sringTypeHistogram.count(type);
|
| }
|
|
|
| -// compressString does nothing but collect UMA so far.
|
| -// TODO(hajimehoshi): Implement this.
|
| void CompressibleStringImpl::compressString()
|
| {
|
| recordCompressibleStringCount(StringWasCompressedInBackgroundTab);
|
| - ASSERT(!isCompressed());
|
| - m_isCompressed = true;
|
| + DCHECK(!isCompressed());
|
| + DCHECK(!m_compressedData);
|
| + DCHECK(!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,8 +139,28 @@ void CompressibleStringImpl::decompressString()
|
| // be complex. See also crbug/581266. We will revisit when the situation
|
| // changes.
|
| recordCompressibleStringCount(StringWasDecompressed);
|
| - ASSERT(isCompressed());
|
| - m_isCompressed = false;
|
| + DCHECK(isCompressed());
|
| + DCHECK(m_compressedData);
|
| + DCHECK(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;
|
| + DCHECK(m_originalLength == m_string.length());
|
| }
|
|
|
| } // namespace blink
|
|
|