mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-28 10:19:26 +00:00 
			
		
		
		
	Merge pull request #5327 from YosysHQ/emil/do_insert-dont-build-new-hash
hashlib: don't build an unused hash for expired value in do_insert
This commit is contained in:
		
						commit
						201c40072c
					
				
					 1 changed files with 3 additions and 7 deletions
				
			
		|  | @ -515,12 +515,11 @@ class dict { | ||||||
| 		return do_lookup_internal(key, hash); | 		return do_lookup_internal(key, hash); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	int do_insert(const K &key, Hasher::hash_t &hash) | 	int do_insert(const K &key, const Hasher::hash_t &hash) | ||||||
| 	{ | 	{ | ||||||
| 		if (hashtable.empty()) { | 		if (hashtable.empty()) { | ||||||
| 			entries.emplace_back(std::pair<K, T>(key, T()), -1); | 			entries.emplace_back(std::pair<K, T>(key, T()), -1); | ||||||
| 			do_rehash(); | 			do_rehash(); | ||||||
| 			hash = do_hash(key); |  | ||||||
| 		} else { | 		} else { | ||||||
| 			entries.emplace_back(std::pair<K, T>(key, T()), hashtable[hash]); | 			entries.emplace_back(std::pair<K, T>(key, T()), hashtable[hash]); | ||||||
| 			hashtable[hash] = entries.size() - 1; | 			hashtable[hash] = entries.size() - 1; | ||||||
|  | @ -528,12 +527,11 @@ class dict { | ||||||
| 		return entries.size() - 1; | 		return entries.size() - 1; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	int do_insert(const std::pair<K, T> &value, Hasher::hash_t &hash) | 	int do_insert(const std::pair<K, T> &value, const Hasher::hash_t &hash) | ||||||
| 	{ | 	{ | ||||||
| 		if (hashtable.empty()) { | 		if (hashtable.empty()) { | ||||||
| 			entries.emplace_back(value, -1); | 			entries.emplace_back(value, -1); | ||||||
| 			do_rehash(); | 			do_rehash(); | ||||||
| 			hash = do_hash(value.first); |  | ||||||
| 		} else { | 		} else { | ||||||
| 			entries.emplace_back(value, hashtable[hash]); | 			entries.emplace_back(value, hashtable[hash]); | ||||||
| 			hashtable[hash] = entries.size() - 1; | 			hashtable[hash] = entries.size() - 1; | ||||||
|  | @ -541,13 +539,11 @@ class dict { | ||||||
| 		return entries.size() - 1; | 		return entries.size() - 1; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	int do_insert(std::pair<K, T> &&rvalue, Hasher::hash_t &hash) | 	int do_insert(std::pair<K, T> &&rvalue, const Hasher::hash_t &hash) | ||||||
| 	{ | 	{ | ||||||
| 		if (hashtable.empty()) { | 		if (hashtable.empty()) { | ||||||
| 			auto key = rvalue.first; |  | ||||||
| 			entries.emplace_back(std::forward<std::pair<K, T>>(rvalue), -1); | 			entries.emplace_back(std::forward<std::pair<K, T>>(rvalue), -1); | ||||||
| 			do_rehash(); | 			do_rehash(); | ||||||
| 			hash = do_hash(key); |  | ||||||
| 		} else { | 		} else { | ||||||
| 			entries.emplace_back(std::forward<std::pair<K, T>>(rvalue), hashtable[hash]); | 			entries.emplace_back(std::forward<std::pair<K, T>>(rvalue), hashtable[hash]); | ||||||
| 			hashtable[hash] = entries.size() - 1; | 			hashtable[hash] = entries.size() - 1; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue