Chromium Code Reviews| Index: third_party/WebKit/Source/platform/text/CompressibleString.h |
| diff --git a/third_party/WebKit/Source/platform/text/CompressibleString.h b/third_party/WebKit/Source/platform/text/CompressibleString.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5ac31d661d3e1d221c80e3cfbd80e682925393b7 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/text/CompressibleString.h |
| @@ -0,0 +1,77 @@ |
| +// 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 CompressibleString_h |
| +#define CompressibleString_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 { |
| + |
| +class WTF_EXPORT CompressibleStringImpl : public RefCounted<CompressibleStringImpl> { |
| + WTF_MAKE_NONCOPYABLE(CompressibleStringImpl); |
| +public: |
| + static void purgeMemory(); |
| + |
| + CompressibleStringImpl(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 contentSizeInBytes() 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 CompressibleString { |
| +public: |
| + CompressibleString(); |
| + CompressibleString(const CompressibleString&); |
| + explicit CompressibleString(PassRefPtr<StringImpl>); |
| + |
| + bool isNull() const { return !m_impl; } |
| + bool isEmpty() const { return m_impl->isEmpty(); } |
|
haraken
2015/11/26 11:50:03
Don't we need to check !m_impl before accessing m_
hajimehoshi
2015/11/27 11:03:58
Done.
|
| + unsigned length() const { return !m_impl ? 0 : m_impl->originalLength(); } |
| + |
| + unsigned contentSizeInBytes() const { return !m_impl ? 0 : m_impl->contentSizeInBytes(); } |
| + |
| + bool isCompressed() const { return m_impl->isCompressed(); } |
| + bool is8Bit() const { return m_impl->is8Bit(); } |
|
haraken
2015/11/26 11:50:03
Ditto.
hajimehoshi
2015/11/27 11:03:58
Done.
|
| + |
| + String toString() const { return m_impl->toString(); } |
| + const LChar* characters8() const { return m_impl->characters8(); } |
| + const UChar* characters16() const { return m_impl->characters16(); } |
|
haraken
2015/11/26 11:50:03
Ditto.
hajimehoshi
2015/11/27 11:03:58
Done.
|
| + |
| + PassRefPtr<CompressibleStringImpl> impl() const { return m_impl; } |
| + |
| +private: |
| + void compress() const; |
| + void uncompress() const; |
| + |
| + mutable RefPtr<CompressibleStringImpl> m_impl; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif |