summaryrefslogtreecommitdiffstats
path: root/base/hash_tables.h
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-13 12:53:16 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-13 12:53:16 +0000
commit1bba09cc68b4f5335ecd335a4e52b74f221ef583 (patch)
treed3d7cbe9c9cfada1a901023b4c50245f559e5fe4 /base/hash_tables.h
parentf3964daf023b2d10df1111248de367a0647d6392 (diff)
downloadchromium_src-1bba09cc68b4f5335ecd335a4e52b74f221ef583.zip
chromium_src-1bba09cc68b4f5335ecd335a4e52b74f221ef583.tar.gz
chromium_src-1bba09cc68b4f5335ecd335a4e52b74f221ef583.tar.bz2
Disable RTTI and C++ exceptions in the Mac build. Disable RTTI in the Linux
build, where C++ exceptions are already disabled. BUG=19094 12248 TEST=Mac release-mode Google Chrome.app should shrink by about 6MB. Mac disk image should shrink by about 1.5MB. Linux binary and package should shrink too. Review URL: http://codereview.chromium.org/165330 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23304 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/hash_tables.h')
-rw-r--r--base/hash_tables.h131
1 files changed, 50 insertions, 81 deletions
diff --git a/base/hash_tables.h b/base/hash_tables.h
index 3f701f0..c2dcde5 100644
--- a/base/hash_tables.h
+++ b/base/hash_tables.h
@@ -12,8 +12,8 @@
// base::hash_set<int> my_set;
//
-#ifndef BASE_HASH_TABLES_H__
-#define BASE_HASH_TABLES_H__
+#ifndef BASE_HASH_TABLES_H_
+#define BASE_HASH_TABLES_H_
#include "build/build_config.h"
@@ -37,99 +37,68 @@ using stdext::hash_set;
#include <ext/hash_map>
#include <ext/hash_set>
+#include <string>
#ifdef CHROME_OLD__DEPRECATED
#define __DEPRECATED CHROME_OLD__DEPRECATED
#undef CHROME_OLD__DEPRECATED
#endif
-#include <tr1/functional>
namespace base {
using __gnu_cxx::hash_map;
using __gnu_cxx::hash_set;
-}
+} // namespace base
-// Implement string hash functions so that strings of various flavors can
-// be used as keys in STL maps and sets.
namespace __gnu_cxx {
-template<>
-struct hash<wchar_t*> {
- size_t operator()(const wchar_t* s) const {
- return std::tr1::hash<const wchar_t*>()(s);
- }
-};
-
-template<>
-struct hash<const wchar_t*> {
- size_t operator()(const wchar_t* s) const {
- return std::tr1::hash<const wchar_t*>()(s);
- }
-};
-
-template<>
-struct hash<std::wstring> {
- size_t operator()(const std::wstring& s) const {
- return std::tr1::hash<std::wstring>()(s);
- }
-};
-
-template<>
-struct hash<const std::wstring> {
- size_t operator()(const std::wstring& s) const {
- return std::tr1::hash<std::wstring>()(s);
- }
-};
-
-template<>
-struct hash<std::string> {
- size_t operator()(const std::string& s) const {
- return std::tr1::hash<std::string>()(s);
- }
-};
-
-template<>
-struct hash<const std::string> {
- size_t operator()(const std::string& s) const {
- return std::tr1::hash<std::string>()(s);
- }
-};
-
-template<>
-struct hash<long long> {
- size_t operator()(long long i) const {
- return std::tr1::hash<long>()((long) i);
- }
-};
+// The GNU C++ library provides identiy hash functions for many integral types,
+// but not for |long long|. This hash function will truncate if |size_t| is
+// narrower than |long long|. This is probably good enough for what we will
+// use it for.
+
+#define DEFINE_TRIVIAL_HASH(integral_type) \
+ template<> \
+ struct hash<integral_type> { \
+ std::size_t operator()(integral_type value) const { \
+ return static_cast<std::size_t>(value); \
+ } \
+ }
+
+DEFINE_TRIVIAL_HASH(long long);
+DEFINE_TRIVIAL_HASH(unsigned long long);
+
+#undef DEFINE_TRIVIAL_HASH
+
+// Implement string hash functions so that strings of various flavors can
+// be used as keys in STL maps and sets. The hash algorithm comes from the
+// GNU C++ library, in <tr1/functional>. It is duplicated here because GCC
+// versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI
+// is disabled, as it is in our build.
+
+#define DEFINE_STRING_HASH(string_type) \
+ template<> \
+ struct hash<string_type> { \
+ std::size_t operator()(const string_type& s) const { \
+ std::size_t result = 0; \
+ for (string_type::const_iterator i = s.begin(); i != s.end(); ++i) \
+ result = (result * 131) + *i; \
+ return result; \
+ } \
+ }
+
+DEFINE_STRING_HASH(std::string);
+DEFINE_STRING_HASH(std::wstring);
#if defined(WCHAR_T_IS_UTF32)
-template<>
-struct hash<string16> {
- size_t operator()(const string16& s) const {
- // This comes from GNU libstdc++, but the types have been changed to
- // make it compile. The lib only defines the hash for string and wstring.
- std::size_t result = 0;
- for (string16::const_iterator i = s.begin(); i != s.end(); ++i)
- result = (result * 131) + *i;
- return result;
- }
-};
-
-template<>
-struct hash<const string16> {
- size_t operator()(const string16& s) const {
- // This comes from GNU libstdc++, but the types have been changed to
- // make it compile. The lib only defines the hash for string and wstring.
- std::size_t result = 0;
- for (string16::const_iterator i = s.begin(); i != s.end(); ++i)
- result = (result * 131) + *i;
- return result;
- }
-};
-#endif
+// If string16 and std::wstring are not the same type, provide a
+// specialization for string16.
+DEFINE_STRING_HASH(string16);
+#endif // WCHAR_T_IS_UTF32
-}
+#undef DEFINE_STRING_HASH
-#endif
+} // namespace __gnu_cxx
+
+#endif // COMPILER
-#endif // BASE_HASH_TABLES_H__
+#endif // BASE_HASH_TABLES_H_