OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 CompressableString_h | |
6 #define CompressableString_h | |
7 | |
8 #include "platform/MemoryPurgeController.h" | |
9 #include "platform/SharedBuffer.h" | |
10 #include "wtf/HashTableDeletedValueType.h" | |
11 #include "wtf/text/Unicode.h" | |
12 #include "wtf/text/WTFString.h" | |
13 | |
14 namespace blink { | |
15 | |
16 struct CompressableStringHash; | |
17 | |
18 class WTF_EXPORT CompressableStringImpl : public RefCounted<CompressableStringIm pl> { | |
haraken
2015/11/24 11:15:42
The design of CompressableStringImpl and Compressa
hajimehoshi
2015/11/26 10:49:13
Thanks.
| |
19 WTF_MAKE_NONCOPYABLE(CompressableStringImpl); | |
20 public: | |
21 static void purgeMemory(); | |
22 | |
23 CompressableStringImpl(PassRefPtr<StringImpl>); | |
24 | |
25 bool isEmpty() const { return m_originalLength == 0; } | |
26 | |
27 PassRefPtr<StringImpl> impl() { return m_impl; } | |
28 PassRefPtr<SharedBuffer> compressedData() { return m_compressedData; } | |
29 bool isCompressed() const { return !!m_compressedData; } | |
30 unsigned originalLength() const { return m_originalLength; } | |
31 bool is8Bit() const { return m_is8Bit; } | |
32 | |
33 unsigned sizeInBytes() const; | |
34 | |
35 String toString(); | |
36 const LChar* characters8(); | |
37 const UChar* characters16(); | |
38 | |
39 void compress(); | |
40 void uncompress(); | |
41 | |
42 private: | |
43 RefPtr<StringImpl> m_impl; | |
44 RefPtr<SharedBuffer> m_compressedData; | |
45 const unsigned m_originalLength; | |
46 const bool m_is8Bit; | |
47 }; | |
48 | |
49 class WTF_EXPORT CompressableString { | |
50 public: | |
51 CompressableString(); | |
52 CompressableString(const CompressableString&); | |
53 explicit CompressableString(PassRefPtr<StringImpl>); | |
54 | |
55 bool isNull() const { return !m_impl; } | |
56 bool isEmpty() const { return !m_impl || m_impl->isEmpty(); } | |
57 unsigned length() const { return !m_impl ? 0 : m_impl->originalLength(); } | |
58 | |
59 // TODO(hajimehoshi): This name is confusing because StringImpl::sizeInBytes | |
60 // includes the size of StringImpl itself but this doesn't. | |
61 unsigned sizeInBytes() const { return !m_impl ? 0 : m_impl->sizeInBytes(); } | |
62 | |
63 bool isCompressed() const { return m_impl->isCompressed(); } | |
64 bool is8Bit() const { return m_impl->is8Bit(); } | |
65 | |
66 String toString() const { return m_impl->toString(); } | |
67 const LChar* characters8() const { return m_impl->characters8(); } | |
68 const UChar* characters16() const { return m_impl->characters16(); } | |
69 | |
70 PassRefPtr<CompressableStringImpl> impl() const { return m_impl; } | |
71 | |
72 private: | |
73 void compress() const; | |
74 void uncompress() const; | |
75 | |
76 mutable RefPtr<CompressableStringImpl> m_impl; | |
77 }; | |
78 | |
79 } // namespace blink | |
80 | |
81 #endif | |
OLD | NEW |