diff options
author | tsepez <tsepez@chromium.org> | 2016-09-15 14:01:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-15 14:01:31 -0700 |
commit | d9871435eb7cea00a173baf780934f9d3525329a (patch) | |
tree | ec96dffc6e25865d6015f754b1a6406621c31bf4 /core/fxcrt/include/cfx_string_pool_template.h | |
parent | 0a17fafd723e8684d1deb4b5ceea58967a0154da (diff) | |
download | pdfium-d9871435eb7cea00a173baf780934f9d3525329a.tar.xz |
Add string pools to save storage.
Adds string hashes so CFX strings will interoperate with
STL unordered containers.
These will be employed per-document in a subsequent cl.
BUG=pdfium:597
Review-Url: https://codereview.chromium.org/2341683005
Diffstat (limited to 'core/fxcrt/include/cfx_string_pool_template.h')
-rw-r--r-- | core/fxcrt/include/cfx_string_pool_template.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core/fxcrt/include/cfx_string_pool_template.h b/core/fxcrt/include/cfx_string_pool_template.h new file mode 100644 index 0000000000..a59d13a61d --- /dev/null +++ b/core/fxcrt/include/cfx_string_pool_template.h @@ -0,0 +1,30 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXCRT_INCLUDE_CFX_STRING_POOL_TEMPLATE_H_ +#define CORE_FXCRT_INCLUDE_CFX_STRING_POOL_TEMPLATE_H_ + +#include <unordered_set> + +#include "core/fxcrt/include/fx_string.h" + +template <typename StringType> +class CFX_StringPoolTemplate { + public: + StringType Intern(const StringType& str) { return *m_Pool.insert(str).first; } + void Clear() { m_Pool.clear(); } + + private: + std::unordered_set<StringType> m_Pool; +}; + +using CFX_ByteStringPool = CFX_StringPoolTemplate<CFX_ByteString>; +using CFX_WideStringPool = CFX_StringPoolTemplate<CFX_WideString>; + +extern template class CFX_StringPoolTemplate<CFX_ByteString>; +extern template class CFX_StringPoolTemplate<CFX_WideString>; + +#endif // CORE_FXCRT_INCLUDE_CFX_STRING_POOL_TEMPLATE_H_ |