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

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

Issue 2130683002: [Experiment] purge-and-suspend Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated Created 4 years, 5 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/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());
esprehn 2016/08/05 23:00:58 ouch this is pretty bad it doubles the memory usag
tasak 2016/08/08 04:47:36 Acknowledged.
+ 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);
esprehn 2016/08/05 23:00:58 ditto
tasak 2016/08/08 04:47:36 Acknowledged.
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698