OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CompressibleString_h | 5 #ifndef CompressibleString_h |
6 #define CompressibleString_h | 6 #define CompressibleString_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "wtf/text/Unicode.h" | 9 #include "wtf/text/Unicode.h" |
10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 // TODO(hajimehoshi): Now these classes are in platform/text to use UMA. Move | 14 // TODO(hajimehoshi): Now these classes are in platform/text to use UMA. Move |
15 // them to wtf/text. | 15 // them to wtf/text. |
16 | 16 |
17 class PLATFORM_EXPORT CompressibleStringImpl final : public RefCounted<Compressi
bleStringImpl> { | 17 class PLATFORM_EXPORT CompressibleStringImpl final : public RefCounted<Compressi
bleStringImpl> { |
18 WTF_MAKE_NONCOPYABLE(CompressibleStringImpl); | 18 WTF_MAKE_NONCOPYABLE(CompressibleStringImpl); |
19 public: | 19 public: |
20 static void compressAll(); | 20 static void compressAll(); |
21 | 21 |
22 CompressibleStringImpl() | 22 CompressibleStringImpl() |
23 : m_string() | 23 : m_string() |
24 , m_isCompressed(false) | 24 , m_originalLength(0) |
| 25 , m_compressedData(nullptr) |
| 26 , m_compressedDataSize(0) |
25 { | 27 { |
26 } | 28 } |
27 | 29 |
28 explicit CompressibleStringImpl(PassRefPtr<StringImpl>); | 30 explicit CompressibleStringImpl(PassRefPtr<StringImpl>); |
29 ~CompressibleStringImpl(); | 31 ~CompressibleStringImpl(); |
30 | 32 |
31 bool isEmpty() const { return originalLength() == 0; } | 33 bool isEmpty() const { return originalLength() == 0; } |
32 | 34 |
33 bool isCompressed() const { return m_isCompressed; } | 35 bool isCompressed() const { return m_compressedData; } |
34 unsigned originalLength() const { return m_string.length(); } | 36 unsigned originalLength() const { return m_string.length(); } |
35 bool is8Bit() const { return m_string.is8Bit(); } | 37 bool is8Bit() const { return m_string.is8Bit(); } |
36 | 38 |
37 unsigned originalContentSizeInBytes() const | 39 unsigned originalContentSizeInBytes() const |
38 { | 40 { |
39 if (is8Bit()) | 41 if (is8Bit()) |
40 return originalLength() * sizeof(LChar); | 42 return originalLength() * sizeof(LChar); |
41 return originalLength() * sizeof(UChar); | 43 return originalLength() * sizeof(UChar); |
42 } | 44 } |
43 | 45 |
(...skipping 18 matching lines...) Expand all Loading... |
62 const UChar* characters16() | 64 const UChar* characters16() |
63 { | 65 { |
64 return toString().characters16(); | 66 return toString().characters16(); |
65 } | 67 } |
66 | 68 |
67 void compressString(); | 69 void compressString(); |
68 void decompressString(); | 70 void decompressString(); |
69 | 71 |
70 private: | 72 private: |
71 String m_string; | 73 String m_string; |
72 bool m_isCompressed; | 74 unsigned m_originalLength; |
| 75 void* m_compressedData; |
| 76 unsigned m_compressedDataSize; |
73 }; | 77 }; |
74 | 78 |
75 class PLATFORM_EXPORT CompressibleString final { | 79 class PLATFORM_EXPORT CompressibleString final { |
76 public: | 80 public: |
77 CompressibleString() | 81 CompressibleString() |
78 : m_impl(nullptr) | 82 : m_impl(nullptr) |
79 { | 83 { |
80 } | 84 } |
81 | 85 |
82 CompressibleString(const CompressibleString& rhs) | 86 CompressibleString(const CompressibleString& rhs) |
(...skipping 27 matching lines...) Expand all Loading... |
110 | 114 |
111 mutable RefPtr<CompressibleStringImpl> m_impl; | 115 mutable RefPtr<CompressibleStringImpl> m_impl; |
112 }; | 116 }; |
113 | 117 |
114 } // namespace blink | 118 } // namespace blink |
115 | 119 |
116 using blink::CompressibleString; | 120 using blink::CompressibleString; |
117 using blink::CompressibleStringImpl; | 121 using blink::CompressibleStringImpl; |
118 | 122 |
119 #endif | 123 #endif |
OLD | NEW |