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