Ver código fonte

Merge pull request #111221 from Ivorforce/ahashmap-no-hashmap-include

Remove `hash_map.h` include from `a_hash_map.h`, and remove cross conversion operators
Thaddeus Crews 4 dias atrás
pai
commit
c01c7b800d
2 arquivos alterados com 21 adições e 22 exclusões
  1. 20 21
      core/templates/a_hash_map.h
  2. 1 1
      scene/animation/animation_mixer.cpp

+ 20 - 21
core/templates/a_hash_map.h

@@ -30,9 +30,14 @@
 
 #pragma once
 
-#include "core/string/ustring.h"
-#include "core/templates/hash_map.h"
+#include "core/os/memory.h"
+#include "core/string/print_string.h"
+#include "core/templates/hashfuncs.h"
+#include "core/templates/pair.h"
 
+#include <initializer_list>
+
+class String;
 class StringName;
 class Variant;
 
@@ -182,8 +187,7 @@ private:
 			if (_metadata[meta_idx].hash == EMPTY_HASH) {
 #ifdef DEV_ENABLED
 				if (unlikely(distance > 12)) {
-					WARN_PRINT("Excessive collision count (" +
-							itos(distance) + "), is the right hash function being used?");
+					WARN_PRINT("Excessive collision count, is the right hash function being used?");
 				}
 #endif
 				_metadata[meta_idx] = metadata;
@@ -657,16 +661,20 @@ public:
 
 	/* Constructors */
 
-	AHashMap(const AHashMap &p_other) {
-		_init_from(p_other);
+	AHashMap(AHashMap &&p_other) {
+		_elements = p_other._elements;
+		_metadata = p_other._metadata;
+		_capacity_mask = p_other._capacity_mask;
+		_size = p_other._size;
+
+		p_other._elements = nullptr;
+		p_other._metadata = nullptr;
+		p_other._capacity_mask = 0;
+		p_other._size = 0;
 	}
 
-	AHashMap(const HashMap<TKey, TValue> &p_other) {
-		reserve(p_other.size());
-		for (const KeyValue<TKey, TValue> &E : p_other) {
-			uint32_t hash = _hash(E.key);
-			_insert_element(E.key, E.value, hash);
-		}
+	AHashMap(const AHashMap &p_other) {
+		_init_from(p_other);
 	}
 
 	void operator=(const AHashMap &p_other) {
@@ -679,15 +687,6 @@ public:
 		_init_from(p_other);
 	}
 
-	void operator=(const HashMap<TKey, TValue> &p_other) {
-		reset();
-		reserve(p_other.size());
-		for (const KeyValue<TKey, TValue> &E : p_other) {
-			uint32_t hash = _hash(E.key);
-			_insert_element(E.key, E.value, hash);
-		}
-	}
-
 	AHashMap(uint32_t p_initial_capacity) {
 		// Capacity can't be 0 and must be 2^n - 1.
 		_capacity_mask = MAX(4u, p_initial_capacity);

+ 1 - 1
scene/animation/animation_mixer.cpp

@@ -2508,7 +2508,7 @@ void AnimatedValuesBackup::set_data(const AHashMap<Animation::TypeHash, Animatio
 }
 
 AHashMap<Animation::TypeHash, AnimationMixer::TrackCache *, HashHasher> AnimatedValuesBackup::get_data() const {
-	HashMap<Animation::TypeHash, AnimationMixer::TrackCache *> ret;
+	AHashMap<Animation::TypeHash, AnimationMixer::TrackCache *, HashHasher> ret;
 	for (const KeyValue<Animation::TypeHash, AnimationMixer::TrackCache *> &E : data) {
 		AnimationMixer::TrackCache *track = get_cache_copy(E.value);
 		ERR_CONTINUE(!track); // Backup shouldn't contain tracks that cannot be copied, this is a mistake.