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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CompressibleString_h
6 #define CompressibleString_h
7
8 #include "wtf/HashTableDeletedValueType.h"
9 #include "wtf/text/Unicode.h"
10 #include "wtf/text/WTFString.h"
11
12 namespace WTF {
13
14 class WTF_EXPORT CompressibleStringImpl : public RefCounted<CompressibleStringIm pl> {
15 WTF_MAKE_NONCOPYABLE(CompressibleStringImpl);
16 public:
17 static void purgeMemory();
18
19 CompressibleStringImpl(PassRefPtr<StringImpl>);
20 ~CompressibleStringImpl();
21
22 bool isEmpty() const { return m_originalLength == 0; }
23
24 PassRefPtr<StringImpl> impl() { return m_impl; }
25 bool isCompressed() const { return !!m_compressedData; }
26 unsigned originalLength() const { return m_originalLength; }
27 bool is8Bit() const { return m_is8Bit; }
28
29 unsigned originalContentSizeInBytes() const;
30 unsigned currentSizeInBytes() const;
31
32 String toString();
33 const LChar* characters8();
34 const UChar* characters16();
35
36 void compressString();
37 void uncompressString();
38
39 private:
40 RefPtr<StringImpl> m_impl;
41 const unsigned m_originalLength;
42 void* m_compressedData;
43 unsigned m_compressedDataSize;
44 const bool m_is8Bit;
45 };
46
47 class WTF_EXPORT CompressibleString {
48 public:
49 CompressibleString();
50 CompressibleString(const CompressibleString&);
51 explicit CompressibleString(PassRefPtr<StringImpl>);
52
53 bool isNull() const { return !m_impl; }
54 bool isEmpty() const { return isNull() || m_impl->isEmpty(); }
55 unsigned length() const { return m_impl ? m_impl->originalLength() : 0; }
56
57 unsigned currentSizeInBytes() const { return m_impl ? m_impl->currentSizeInB ytes() : 0; }
58
59 bool isCompressed() const { return m_impl ? m_impl->isCompressed() : false; }
60 bool is8Bit() const { return m_impl->is8Bit(); }
61
62 String toString() const { return m_impl ? m_impl->toString() : String(); }
63 const LChar* characters8() const { return m_impl ? m_impl->characters8() : n ullptr; }
64 const UChar* characters16() const { return m_impl ? m_impl->characters16() : nullptr; }
65
66 PassRefPtr<CompressibleStringImpl> impl() const { return m_impl; }
67
68 private:
69 void compressString() const;
70 void uncompressString() const;
71
72 mutable RefPtr<CompressibleStringImpl> m_impl;
73 };
74
75 } // namespace WTF
76
77 using WTF::CompressibleString;
78 using WTF::CompressibleStringImpl;
79
80 #endif
OLDNEW
« 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