summaryrefslogtreecommitdiff
path: root/core/fxcrt/include/fx_string.h
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/fx_string.h
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/fx_string.h')
-rw-r--r--core/fxcrt/include/fx_string.h30
1 files changed, 30 insertions, 0 deletions
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_