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

Unified Diff: third_party/WebKit/Source/wtf/text/CompressibleString.h

Issue 1389383003: WIP: Introduce CompressibleString Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase onto crrev.com/1564773002 Created 4 years, 11 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/wtf/text/CompressibleString.h
diff --git a/third_party/WebKit/Source/wtf/text/CompressibleString.h b/third_party/WebKit/Source/wtf/text/CompressibleString.h
new file mode 100644
index 0000000000000000000000000000000000000000..8942beb18fa4c91a5299d08f66a736a1724899ee
--- /dev/null
+++ b/third_party/WebKit/Source/wtf/text/CompressibleString.h
@@ -0,0 +1,80 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CompressibleString_h
+#define CompressibleString_h
+
+#include "wtf/HashTableDeletedValueType.h"
+#include "wtf/text/Unicode.h"
+#include "wtf/text/WTFString.h"
+
+namespace WTF {
+
+class WTF_EXPORT CompressibleStringImpl : public RefCounted<CompressibleStringImpl> {
+ WTF_MAKE_NONCOPYABLE(CompressibleStringImpl);
+public:
+ static void purgeMemory();
+
+ CompressibleStringImpl(PassRefPtr<StringImpl>);
+ ~CompressibleStringImpl();
+
+ bool isEmpty() const { return m_originalLength == 0; }
+
+ PassRefPtr<StringImpl> impl() { return m_impl; }
+ bool isCompressed() const { return !!m_compressedData; }
+ unsigned originalLength() const { return m_originalLength; }
+ bool is8Bit() const { return m_is8Bit; }
+
+ unsigned originalContentSizeInBytes() const;
+ unsigned currentSizeInBytes() const;
+
+ String toString();
+ const LChar* characters8();
+ const UChar* characters16();
+
+ void compressString();
+ void uncompressString();
+
+private:
+ RefPtr<StringImpl> m_impl;
+ const unsigned m_originalLength;
+ void* m_compressedData;
+ unsigned m_compressedDataSize;
+ const bool m_is8Bit;
+};
+
+class WTF_EXPORT CompressibleString {
+public:
+ CompressibleString();
+ CompressibleString(const CompressibleString&);
+ explicit CompressibleString(PassRefPtr<StringImpl>);
+
+ bool isNull() const { return !m_impl; }
+ bool isEmpty() const { return isNull() || m_impl->isEmpty(); }
+ unsigned length() const { return m_impl ? m_impl->originalLength() : 0; }
+
+ unsigned currentSizeInBytes() const { return m_impl ? m_impl->currentSizeInBytes() : 0; }
+
+ bool isCompressed() const { return m_impl ? m_impl->isCompressed() : false; }
+ bool is8Bit() const { return m_impl->is8Bit(); }
+
+ String toString() const { return m_impl ? m_impl->toString() : String(); }
+ const LChar* characters8() const { return m_impl ? m_impl->characters8() : nullptr; }
+ const UChar* characters16() const { return m_impl ? m_impl->characters16() : nullptr; }
+
+ PassRefPtr<CompressibleStringImpl> impl() const { return m_impl; }
+
+private:
+ void compressString() const;
+ void uncompressString() const;
+
+ mutable RefPtr<CompressibleStringImpl> m_impl;
+};
+
+} // namespace WTF
+
+using WTF::CompressibleString;
+using WTF::CompressibleStringImpl;
+
+#endif
« no previous file with comments | « third_party/WebKit/Source/wtf/WTFThreadData.cpp ('k') | third_party/WebKit/Source/wtf/text/CompressibleString.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698