Daniele Bartolini 8 лет назад
Родитель
Сommit
2581147dc5

+ 2 - 22
src/core/containers/container_types.h

@@ -124,17 +124,7 @@ struct HashMap
 {
 	ALLOCATOR_AWARE;
 
-	struct Entry
-	{
-		ALLOCATOR_AWARE;
-
-		PAIR(TKey, TValue) pair;
-
-		Entry(Allocator& a)
-			: pair(a)
-		{
-		}
-	};
+	typedef PAIR(TKey, TValue) Entry;
 
 	struct Index
 	{
@@ -166,17 +156,7 @@ struct SortMap
 {
 	ALLOCATOR_AWARE;
 
-	struct Entry
-	{
-		ALLOCATOR_AWARE;
-
-		PAIR(TKey, TValue) pair;
-
-		Entry(Allocator& a)
-			: pair(a)
-		{
-		}
-	};
+	typedef PAIR(TKey, TValue) Entry;
 
 	Vector<Entry> _data;
 #if CROWN_DEBUG

+ 8 - 8
src/core/containers/hash_map.h

@@ -87,7 +87,7 @@ namespace hash_map_internal
 				return END_OF_LIST;
 			else if (dist > probe_distance(m, m._index[hash_i].hash, hash_i))
 				return END_OF_LIST;
-			else if (!is_deleted(m._index[hash_i].index) && m._index[hash_i].hash == hash && m._data[hash_i].pair.first == key)
+			else if (!is_deleted(m._index[hash_i].index) && m._index[hash_i].hash == hash && m._data[hash_i].first == key)
 				return hash_i;
 
 			hash_i = (hash_i + 1) & m._mask;
@@ -119,7 +119,7 @@ namespace hash_map_internal
 
 				std::swap(hash, m._index[hash_i].hash);
 				m._index[hash_i].index = 0x0123abcd;
-				swap(new_item, m._data[hash_i].pair);
+				swap(new_item, m._data[hash_i]);
 
 				dist = existing_elem_probe_dist;
 			}
@@ -165,7 +165,7 @@ namespace hash_map_internal
 			const u32 index = m._index[i].index;
 
 			if (index != FREE && !is_deleted(index))
-				hash_map_internal::insert(nm, hash, e.pair.first, e.pair.second);
+				hash_map_internal::insert(nm, hash, e.first, e.second);
 		}
 
 		HashMap<TKey, TValue, Hash> empty(*m._allocator);
@@ -216,7 +216,7 @@ namespace hash_map
 		if (i == hash_map_internal::END_OF_LIST)
 			return deffault;
 		else
-			return m._data[i].pair.second;
+			return m._data[i].second;
 	}
 
 	template <typename TKey, typename TValue, typename Hash>
@@ -234,7 +234,7 @@ namespace hash_map
 		}
 		else
 		{
-			m._data[i].pair.second = value;
+			m._data[i].second = value;
 		}
 		if (hash_map_internal::full(m))
 			hash_map_internal::grow(m);
@@ -247,7 +247,7 @@ namespace hash_map
 		if (i == hash_map_internal::END_OF_LIST)
 			return;
 
-		m._data[i].~Entry();
+		m._data[i].~Pair();
 		m._index[i].index |= hash_map_internal::DELETED;
 		--m._size;
 	}
@@ -258,7 +258,7 @@ namespace hash_map
 		for (u32 i = 0; i < m._capacity; ++i)
 		{
 			if (m._index[i].index == 0x0123abcd)
-				m._data[i].~Entry();
+				m._data[i].~Pair();
 			m._index[i].index = hash_map_internal::FREE;
 		}
 
@@ -284,7 +284,7 @@ HashMap<TKey, TValue, Hash>::~HashMap()
 	for (u32 i = 0; i < _capacity; ++i)
 	{
 		if (_index[i].index == 0x0123abcd)
-			_data[i].~Entry();
+			_data[i].~Pair();
 	}
 
 	_allocator->deallocate(_index);

+ 7 - 7
src/core/containers/sort_map.h

@@ -62,13 +62,13 @@ namespace sort_map_internal
 		bool operator()(const typename SortMap<TKey, TValue, Compare>::Entry& a,
 			const typename SortMap<TKey, TValue, Compare>::Entry& b) const
 		{
-			return comp(a.pair.first, b.pair.first);
+			return comp(a.first, b.first);
 		}
 
 		bool operator()(const typename SortMap<TKey, TValue, Compare>::Entry& a,
 			const TKey& key) const
 		{
-			return comp(a.pair.first, key);
+			return comp(a.first, key);
 		}
 
 		Compare comp;
@@ -86,7 +86,7 @@ namespace sort_map_internal
 			std::lower_bound(vector::begin(m._data), vector::end(m._data), key,
 			sort_map_internal::CompareEntry<TKey, TValue, Compare>());
 
-		if (first != vector::end(m._data) && !(key < first->pair.first))
+		if (first != vector::end(m._data) && !(key < first->first))
 			result.item_i = u32(first - vector::begin(m._data));
 
 		return result;
@@ -116,7 +116,7 @@ namespace sort_map
 		if (result.item_i == sort_map_internal::END_OF_LIST)
 			return deffault;
 
-		return m._data[result.item_i].pair.second;
+		return m._data[result.item_i].second;
 	}
 
 	template <typename TKey, typename TValue, typename Compare>
@@ -143,13 +143,13 @@ namespace sort_map
 		if (result.item_i == sort_map_internal::END_OF_LIST)
 		{
 			typename SortMap<TKey, TValue, Compare>::Entry e(*m._data._allocator);
-			e.pair.first = key;
-			e.pair.second = val;
+			e.first = key;
+			e.second = val;
 			vector::push_back(m._data, e);
 		}
 		else
 		{
-			m._data[result.item_i].pair.second = val;
+			m._data[result.item_i].second = val;
 		}
 #if CROWN_DEBUG
 		m._is_sorted = false;

+ 8 - 0
src/core/pair.h

@@ -18,6 +18,8 @@ struct Pair
 template <typename T1, typename T2>
 struct Pair<T1, T2, 0, 0>
 {
+	ALLOCATOR_AWARE;
+
 	Pair(T1& f, T2& s)
 		: first(f)
 		, second(s)
@@ -35,6 +37,8 @@ struct Pair<T1, T2, 0, 0>
 template <typename T1, typename T2>
 struct Pair<T1, T2, 1, 0>
 {
+	ALLOCATOR_AWARE;
+
 	Pair(T1& f, T2& s)
 		: first(f)
 		, second(s)
@@ -53,6 +57,8 @@ struct Pair<T1, T2, 1, 0>
 template <typename T1, typename T2>
 struct Pair<T1, T2, 0, 1>
 {
+	ALLOCATOR_AWARE;
+
 	Pair(T1& f, T2& s)
 		: first(f)
 		, second(s)
@@ -71,6 +77,8 @@ struct Pair<T1, T2, 0, 1>
 template <typename T1, typename T2>
 struct Pair<T1, T2, 1, 1>
 {
+	ALLOCATOR_AWARE;
+
 	Pair(T1& f, T2& s)
 		: first(f)
 		, second(s)

+ 3 - 3
src/resource/resource_manager.cpp

@@ -29,10 +29,10 @@ ResourceManager::~ResourceManager()
 	auto end = sort_map::end(_rm);
 	for (; cur != end; ++cur)
 	{
-		const StringId64 type = cur->pair.first.type;
-		const StringId64 name = cur->pair.first.name;
+		const StringId64 type = cur->first.type;
+		const StringId64 name = cur->first.name;
 		on_offline(type, name);
-		on_unload(type, cur->pair.second.data);
+		on_unload(type, cur->second.data);
 	}
 }
 

+ 1 - 1
src/resource/unit_compiler.cpp

@@ -357,7 +357,7 @@ Buffer UnitCompiler::blob()
 	auto end = sort_map::end(_component_data);
 	for (; cur != end; ++cur)
 	{
-		const u32 num = cur->pair.second._num;
+		const u32 num = cur->second._num;
 
 		if (num > 0)
 			++ur.num_component_types;

+ 1 - 1
src/world/material_manager.cpp

@@ -26,7 +26,7 @@ MaterialManager::~MaterialManager()
 	auto end = sort_map::end(_materials);
 	for (; cur != end; ++cur)
 	{
-		_allocator->deallocate(cur->pair.second);
+		_allocator->deallocate(cur->second);
 	}
 }