Commit d4556dfc by Kai Ninomiya Committed by Commit Bot

Reland 'Adds TUnorderedMap and uses it for tLevel in TSymbolTableLevel.'

Reland of https://crrev.com/c/526672 Bug: 697758 Change-Id: I410e4774c4ad85595eb8789603901878b209c857 Reviewed-on: https://chromium-review.googlesource.com/688296Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
parent 54118be6
......@@ -10,12 +10,14 @@
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
#include <limits>
#include <stdio.h>
#include "common/angleutils.h"
#include "common/debug.h"
#include "common/third_party/smhasher/src/PMurHash.h"
#include "compiler/translator/PoolAlloc.h"
namespace sh
......@@ -76,6 +78,23 @@ class TVector : public std::vector<T, pool_allocator<T>>
TVector(size_type i) : std::vector<T, pool_allocator<T>>(i) {}
};
template <class K, class D, class H = std::hash<K>, class CMP = std::equal_to<K>>
class TUnorderedMap : public std::unordered_map<K, D, H, CMP, pool_allocator<std::pair<const K, D>>>
{
public:
POOL_ALLOCATOR_NEW_DELETE();
typedef pool_allocator<std::pair<const K, D>> tAllocator;
TUnorderedMap() : std::unordered_map<K, D, H, CMP, tAllocator>() {}
// use correct two-stage name lookup supported in gcc 3.4 and above
TUnorderedMap(const tAllocator &a)
: std::unordered_map<K, D, H, CMP, tAllocator>(
std::unordered_map<K, D, H, CMP, tAllocator>::key_compare(),
a)
{
}
};
template <class K, class D, class CMP = std::less<K>>
class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<const K, D>>>
{
......@@ -104,4 +123,16 @@ inline TString str(T i)
} // namespace sh
namespace std
{
template <>
struct hash<sh::TString>
{
size_t operator()(const sh::TString &s) const
{
return angle::PMurHash32(0, s.data(), static_cast<int>(s.length()));
}
};
} // namespace std
#endif // COMPILER_TRANSLATOR_COMMON_H_
......@@ -227,7 +227,7 @@ class TInterfaceBlockName : public TSymbol
class TSymbolTableLevel
{
public:
typedef TMap<TString, TSymbol *> tLevel;
typedef TUnorderedMap<TString, TSymbol *> tLevel;
typedef tLevel::const_iterator const_iterator;
typedef const tLevel::value_type tLevelPair;
typedef std::pair<tLevel::iterator, bool> tInsertResult;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment