summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2010-03-03 01:23:07 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2010-03-03 01:23:07 +0000
commit5d279b6df2658c28ae89e52285869bf175409430 (patch)
tree3329226f144f6bdb710d63d9991072e85c273791
parent3b718636c37ddaa8c6867bb341d00f7494cd6770 (diff)
downloadgcc-5d279b6df2658c28ae89e52285869bf175409430.tar.gz
2010-03-02 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/functional_hash.h (_Fnv_hash_base<>::hash): Change to template. * include/tr1/functional_hash.h (_Fnv_hash_base<>::hash): Likewise. * include/bits/vector.tcc (hash): Adjust. * include/bits/basic_string.h (hash): Likewise. * include/std/bitset (hash): Likewise. * src/hash-string-aux.cc (hash): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157185 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog10
-rw-r--r--libstdc++-v3/include/bits/basic_string.h18
-rw-r--r--libstdc++-v3/include/bits/functional_hash.h72
-rw-r--r--libstdc++-v3/include/bits/vector.tcc13
-rw-r--r--libstdc++-v3/include/std/bitset12
-rw-r--r--libstdc++-v3/include/tr1/functional_hash.h71
-rw-r--r--libstdc++-v3/src/hash-string-aux.cc10
7 files changed, 105 insertions, 101 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 86e26475f51..f8c19e4d3aa 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,13 @@
+2010-03-02 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/functional_hash.h (_Fnv_hash_base<>::hash): Change
+ to template.
+ * include/tr1/functional_hash.h (_Fnv_hash_base<>::hash): Likewise.
+ * include/bits/vector.tcc (hash): Adjust.
+ * include/bits/basic_string.h (hash): Likewise.
+ * include/std/bitset (hash): Likewise.
+ * src/hash-string-aux.cc (hash): Likewise.
+
2010-03-02 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/std/mutex (lock_guard::lock_guard): Do not lock mutex when
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 4c1c427f142..312d4ed6cb6 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -2898,10 +2898,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
size_t
operator()(const wstring& __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return std::_Fnv_hash::hash(__p, __s.length() * sizeof(wchar_t));
- }
+ { return std::_Fnv_hash::hash(__s.data(),
+ __s.length() * sizeof(wchar_t)); }
};
#endif
#endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
@@ -2914,10 +2912,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
size_t
operator()(const u16string& __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return std::_Fnv_hash::hash(__p, __s.length() * sizeof(char16_t));
- }
+ { return std::_Fnv_hash::hash(__s.data(),
+ __s.length() * sizeof(char16_t)); }
};
/// std::hash specialization for u32string.
@@ -2927,10 +2923,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
size_t
operator()(const u32string& __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return std::_Fnv_hash::hash(__p, __s.length() * sizeof(char32_t));
- }
+ { return std::_Fnv_hash::hash(__s.data(),
+ __s.length() * sizeof(char32_t)); }
};
#endif
diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h
index 41fe11fae8f..aaa05aad689 100644
--- a/libstdc++-v3/include/bits/functional_hash.h
+++ b/libstdc++-v3/include/bits/functional_hash.h
@@ -122,45 +122,51 @@ namespace std
template<size_t>
struct _Fnv_hash_base
{
- static size_t
- hash(const char* __first, size_t __length, size_t __hash = 0)
- {
- for (; __length; --__length)
- __hash = (__hash * 131) + *__first++;
- return __hash;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength, size_t __hash = 0)
+ {
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ __hash = (__hash * 131) + *__cptr++;
+ return __hash;
+ }
};
template<>
struct _Fnv_hash_base<4>
{
- static size_t
- hash(const char* __first, size_t __length,
- size_t __hash = static_cast<size_t>(2166136261UL))
- {
- for (; __length; --__length)
- {
- __hash ^= static_cast<size_t>(*__first++);
- __hash *= static_cast<size_t>(16777619UL);
- }
- return __hash;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength,
+ size_t __hash = static_cast<size_t>(2166136261UL))
+ {
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ {
+ __hash ^= static_cast<size_t>(*__cptr++);
+ __hash *= static_cast<size_t>(16777619UL);
+ }
+ return __hash;
+ }
};
template<>
struct _Fnv_hash_base<8>
{
- static size_t
- hash(const char* __first, size_t __length,
- size_t __hash = static_cast<size_t>(14695981039346656037ULL))
- {
- for (; __length; --__length)
- {
- __hash ^= static_cast<size_t>(*__first++);
- __hash *= static_cast<size_t>(1099511628211ULL);
- }
- return __hash;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength,
+ size_t __hash = static_cast<size_t>(14695981039346656037ULL))
+ {
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ {
+ __hash ^= static_cast<size_t>(*__cptr++);
+ __hash *= static_cast<size_t>(1099511628211ULL);
+ }
+ return __hash;
+ }
};
struct _Fnv_hash
@@ -171,14 +177,12 @@ namespace std
template<typename _Tp>
static size_t
hash(const _Tp& __val)
- { return hash(reinterpret_cast<const char*>(&__val),
- sizeof(__val)); }
+ { return hash(&__val, sizeof(__val)); }
template<typename _Tp>
static size_t
__hash_combine(const _Tp& __val, size_t __hash)
- { return hash(reinterpret_cast<const char*>(&__val),
- sizeof(__val), __hash); }
+ { return hash(&__val, sizeof(__val), __hash); }
};
/// Specialization for float.
@@ -201,7 +205,7 @@ namespace std
/// Specialization for long double.
template<>
- size_t
+ _GLIBCXX_PURE size_t
hash<long double>::operator()(long double __val) const;
// @} group hashes
diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc
index 984f83f3c9e..e1097931048 100644
--- a/libstdc++-v3/include/bits/vector.tcc
+++ b/libstdc++-v3/include/bits/vector.tcc
@@ -694,10 +694,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const size_t __words = __b.size() / _S_word_bit;
if (__words)
{
- const char* __data
- = reinterpret_cast<const char*>(__b._M_impl._M_start._M_p);
- const size_t __size = __words * sizeof(_Bit_type);
- __hash = std::_Fnv_hash::hash(__data, __size);
+ const size_t __clength = __words * sizeof(_Bit_type);
+ __hash = std::_Fnv_hash::hash(__b._M_impl._M_start._M_p, __clength);
}
const size_t __extrabits = __b.size() % _S_word_bit;
@@ -706,13 +704,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Bit_type __hiword = *__b._M_impl._M_finish._M_p;
__hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
- const char* __data = reinterpret_cast<const char*>(&__hiword);
- const size_t __size
+ const size_t __clength
= (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
if (__words)
- __hash = std::_Fnv_hash::hash(__data, __size, __hash);
+ __hash = std::_Fnv_hash::hash(&__hiword, __clength, __hash);
else
- __hash = std::_Fnv_hash::hash(__data, __size);
+ __hash = std::_Fnv_hash::hash(&__hiword, __clength);
}
return __hash;
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index 7372639c58a..b23b51a78fe 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -115,9 +115,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
{ return _M_w[_S_whichword(__pos)]; }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
- const char*
+ const _WordT*
_M_getdata() const
- { return reinterpret_cast<const char*>(_M_w); }
+ { return _M_w; }
#endif
_WordT&
@@ -406,9 +406,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
{ return _M_w; }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
- const char*
+ const _WordT*
_M_getdata() const
- { return reinterpret_cast<const char*>(&_M_w); }
+ { return &_M_w; }
#endif
_WordT&
@@ -1501,8 +1501,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
size_t
operator()(const _GLIBCXX_STD_D::bitset<_Nb>& __b) const
{
- const size_t __size = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
- return std::_Fnv_hash::hash(__b._M_getdata(), __size);
+ const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
+ return std::_Fnv_hash::hash(__b._M_getdata(), __clength);
}
};
diff --git a/libstdc++-v3/include/tr1/functional_hash.h b/libstdc++-v3/include/tr1/functional_hash.h
index 98fb1878695..9ea483e3e38 100644
--- a/libstdc++-v3/include/tr1/functional_hash.h
+++ b/libstdc++-v3/include/tr1/functional_hash.h
@@ -85,47 +85,53 @@ namespace tr1
template<size_t>
struct _Fnv_hash_base
{
- static size_t
- hash(const char* __first, size_t __length)
- {
- size_t __result = 0;
- for (; __length > 0; --__length)
- __result = (__result * 131) + *__first++;
- return __result;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength)
+ {
+ size_t __result = 0;
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ __result = (__result * 131) + *__cptr++;
+ return __result;
+ }
};
template<>
struct _Fnv_hash_base<4>
{
- static size_t
- hash(const char* __first, size_t __length)
- {
- size_t __result = static_cast<size_t>(2166136261UL);
- for (; __length > 0; --__length)
- {
- __result ^= static_cast<size_t>(*__first++);
- __result *= static_cast<size_t>(16777619UL);
- }
- return __result;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength)
+ {
+ size_t __result = static_cast<size_t>(2166136261UL);
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ {
+ __result ^= static_cast<size_t>(*__cptr++);
+ __result *= static_cast<size_t>(16777619UL);
+ }
+ return __result;
+ }
};
template<>
struct _Fnv_hash_base<8>
{
- static size_t
- hash(const char* __first, size_t __length)
- {
- size_t __result =
- static_cast<size_t>(14695981039346656037ULL);
- for (; __length > 0; --__length)
- {
- __result ^= static_cast<size_t>(*__first++);
- __result *= static_cast<size_t>(1099511628211ULL);
- }
- return __result;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength)
+ {
+ size_t __result
+ = static_cast<size_t>(14695981039346656037ULL);
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ {
+ __result ^= static_cast<size_t>(*__cptr++);
+ __result *= static_cast<size_t>(1099511628211ULL);
+ }
+ return __result;
+ }
};
struct _Fnv_hash
@@ -136,8 +142,7 @@ namespace tr1
template<typename _Tp>
static size_t
hash(const _Tp& __val)
- { return hash(reinterpret_cast<const char*>(&__val),
- sizeof(__val)); }
+ { return hash(&__val, sizeof(__val)); }
};
/// Explicit specializations for float.
diff --git a/libstdc++-v3/src/hash-string-aux.cc b/libstdc++-v3/src/hash-string-aux.cc
index b5a2c6ddc3d..711d7f41c9d 100644
--- a/libstdc++-v3/src/hash-string-aux.cc
+++ b/libstdc++-v3/src/hash-string-aux.cc
@@ -37,18 +37,12 @@
template<>
size_t
hash<wstring>::operator()(wstring __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return _Fnv_hash::hash(__p, __s.length() * sizeof(wchar_t));
- }
+ { return _Fnv_hash::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
template<>
size_t
hash<const wstring&>::operator()(const wstring& __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return _Fnv_hash::hash(__p, __s.length() * sizeof(wchar_t));
- }
+ { return _Fnv_hash::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
#endif
#endif