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

Unified Diff: third_party/WebKit/Source/platform/text/CompressibleString.cpp

Issue 1670113002: DO NOT COMMIT: Actual compression in CompressibleString Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/platform/text/CompressibleString.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « third_party/WebKit/Source/platform/text/CompressibleString.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698