Chromium Code Reviews| Index: third_party/WebKit/Source/platform/text/CompressableString.h |
| diff --git a/third_party/WebKit/Source/platform/text/CompressableString.h b/third_party/WebKit/Source/platform/text/CompressableString.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8e3ac475af7a074a0bd5456bc62e0b5d5f345aef |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/text/CompressableString.h |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2015 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 CompressableString_h |
| +#define CompressableString_h |
| + |
| +#include "platform/MemoryPurgeController.h" |
| +#include "platform/SharedBuffer.h" |
| +#include "wtf/HashTableDeletedValueType.h" |
| +#include "wtf/text/Unicode.h" |
| +#include "wtf/text/WTFString.h" |
| + |
| +namespace blink { |
| + |
| +struct CompressableStringHash; |
| + |
| +class WTF_EXPORT CompressableStringImpl : public RefCounted<CompressableStringImpl> { |
|
haraken
2015/11/24 11:15:42
The design of CompressableStringImpl and Compressa
hajimehoshi
2015/11/26 10:49:13
Thanks.
|
| + WTF_MAKE_NONCOPYABLE(CompressableStringImpl); |
| +public: |
| + static void purgeMemory(); |
| + |
| + CompressableStringImpl(PassRefPtr<StringImpl>); |
| + |
| + bool isEmpty() const { return m_originalLength == 0; } |
| + |
| + PassRefPtr<StringImpl> impl() { return m_impl; } |
| + PassRefPtr<SharedBuffer> compressedData() { return m_compressedData; } |
| + bool isCompressed() const { return !!m_compressedData; } |
| + unsigned originalLength() const { return m_originalLength; } |
| + bool is8Bit() const { return m_is8Bit; } |
| + |
| + unsigned sizeInBytes() const; |
| + |
| + String toString(); |
| + const LChar* characters8(); |
| + const UChar* characters16(); |
| + |
| + void compress(); |
| + void uncompress(); |
| + |
| +private: |
| + RefPtr<StringImpl> m_impl; |
| + RefPtr<SharedBuffer> m_compressedData; |
| + const unsigned m_originalLength; |
| + const bool m_is8Bit; |
| +}; |
| + |
| +class WTF_EXPORT CompressableString { |
| +public: |
| + CompressableString(); |
| + CompressableString(const CompressableString&); |
| + explicit CompressableString(PassRefPtr<StringImpl>); |
| + |
| + bool isNull() const { return !m_impl; } |
| + bool isEmpty() const { return !m_impl || m_impl->isEmpty(); } |
| + unsigned length() const { return !m_impl ? 0 : m_impl->originalLength(); } |
| + |
| + // TODO(hajimehoshi): This name is confusing because StringImpl::sizeInBytes |
| + // includes the size of StringImpl itself but this doesn't. |
| + unsigned sizeInBytes() const { return !m_impl ? 0 : m_impl->sizeInBytes(); } |
| + |
| + bool isCompressed() const { return m_impl->isCompressed(); } |
| + bool is8Bit() const { return m_impl->is8Bit(); } |
| + |
| + String toString() const { return m_impl->toString(); } |
| + const LChar* characters8() const { return m_impl->characters8(); } |
| + const UChar* characters16() const { return m_impl->characters16(); } |
| + |
| + PassRefPtr<CompressableStringImpl> impl() const { return m_impl; } |
| + |
| +private: |
| + void compress() const; |
| + void uncompress() const; |
| + |
| + mutable RefPtr<CompressableStringImpl> m_impl; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif |