summaryrefslogtreecommitdiff
path: root/core/fxcrt/include
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-09-15 14:01:31 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-15 14:01:31 -0700
commitd9871435eb7cea00a173baf780934f9d3525329a (patch)
treeec96dffc6e25865d6015f754b1a6406621c31bf4 /core/fxcrt/include
parent0a17fafd723e8684d1deb4b5ceea58967a0154da (diff)
downloadpdfium-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')
-rw-r--r--core/fxcrt/include/cfx_string_pool_template.h30
-rw-r--r--core/fxcrt/include/fx_ext.h10
-rw-r--r--core/fxcrt/include/fx_string.h30
3 files changed, 61 insertions, 9 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_
diff --git a/core/fxcrt/include/fx_ext.h b/core/fxcrt/include/fx_ext.h
index f7aca68d64..e33d57bdb7 100644
--- a/core/fxcrt/include/fx_ext.h
+++ b/core/fxcrt/include/fx_ext.h
@@ -83,19 +83,11 @@ inline int FXSYS_toDecimalDigit(const FX_WCHAR c) {
FX_FLOAT FXSYS_FractionalScale(size_t scale_factor, int value);
int FXSYS_FractionalScaleCount();
-uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase);
-uint32_t FX_HashCode_GetW(const CFX_WideStringC& Str, bool bIgnoreCase);
-
void* FX_Random_MT_Start(uint32_t dwSeed);
-
-uint32_t FX_Random_MT_Generate(void* pContext);
-
void FX_Random_MT_Close(void* pContext);
-
+uint32_t FX_Random_MT_Generate(void* pContext);
void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount);
-
void FX_Random_GenerateMT(uint32_t* pBuffer, int32_t iCount);
-
void FX_Random_GenerateCrypto(uint32_t* pBuffer, int32_t iCount);
#ifdef PDF_ENABLE_XFA
diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h
index 48378586d3..6e9af221ca 100644
--- a/core/fxcrt/include/fx_string.h
+++ b/core/fxcrt/include/fx_string.h
@@ -8,7 +8,9 @@
#define CORE_FXCRT_INCLUDE_FX_STRING_H_
#include <stdint.h> // For intptr_t.
+
#include <algorithm>
+#include <functional>
#include "core/fxcrt/cfx_string_c_template.h"
#include "core/fxcrt/cfx_string_data_template.h"
@@ -166,7 +168,9 @@ class CFX_ByteString {
void Concat(const FX_CHAR* lpszSrcData, FX_STRSIZE nSrcLen);
CFX_RetainPtr<StringData> m_pData;
+
friend class fxcrt_ByteStringConcat_Test;
+ friend class fxcrt_ByteStringPool_Test;
};
inline bool operator==(const char* lhs, const CFX_ByteString& rhs) {
@@ -357,7 +361,9 @@ class CFX_WideString {
void Concat(const FX_WCHAR* lpszSrcData, FX_STRSIZE nSrcLen);
CFX_RetainPtr<StringData> m_pData;
+
friend class fxcrt_WideStringConcatInPlace_Test;
+ friend class fxcrt_WideStringPool_Test;
};
inline CFX_WideString operator+(const CFX_WideStringC& str1,
@@ -432,4 +438,28 @@ inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) {
bool FX_atonum(const CFX_ByteStringC& str, void* pData);
FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf);
+uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase);
+uint32_t FX_HashCode_GetW(const CFX_WideStringC& str, bool bIgnoreCase);
+
+namespace std {
+
+template <>
+struct hash<CFX_ByteString> {
+ std::size_t operator()(const CFX_ByteString& str) const {
+ return FX_HashCode_GetA(str.AsStringC(), false);
+ }
+};
+
+template <>
+struct hash<CFX_WideString> {
+ std::size_t operator()(const CFX_WideString& str) const {
+ return FX_HashCode_GetW(str.AsStringC(), false);
+ }
+};
+
+} // namespace std
+
+extern template struct std::hash<CFX_ByteString>;
+extern template struct std::hash<CFX_WideString>;
+
#endif // CORE_FXCRT_INCLUDE_FX_STRING_H_