Skip to content

Commit 201c400

Browse files
authored
Merge pull request YosysHQ#5327 from YosysHQ/emil/do_insert-dont-build-new-hash
hashlib: don't build an unused hash for expired value in do_insert
2 parents 5278b9c + ccf140f commit 201c400

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

kernel/hashlib.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,39 +515,35 @@ class dict {
515515
return do_lookup_internal(key, hash);
516516
}
517517

518-
int do_insert(const K &key, Hasher::hash_t &hash)
518+
int do_insert(const K &key, const Hasher::hash_t &hash)
519519
{
520520
if (hashtable.empty()) {
521521
entries.emplace_back(std::pair<K, T>(key, T()), -1);
522522
do_rehash();
523-
hash = do_hash(key);
524523
} else {
525524
entries.emplace_back(std::pair<K, T>(key, T()), hashtable[hash]);
526525
hashtable[hash] = entries.size() - 1;
527526
}
528527
return entries.size() - 1;
529528
}
530529

531-
int do_insert(const std::pair<K, T> &value, Hasher::hash_t &hash)
530+
int do_insert(const std::pair<K, T> &value, const Hasher::hash_t &hash)
532531
{
533532
if (hashtable.empty()) {
534533
entries.emplace_back(value, -1);
535534
do_rehash();
536-
hash = do_hash(value.first);
537535
} else {
538536
entries.emplace_back(value, hashtable[hash]);
539537
hashtable[hash] = entries.size() - 1;
540538
}
541539
return entries.size() - 1;
542540
}
543541

544-
int do_insert(std::pair<K, T> &&rvalue, Hasher::hash_t &hash)
542+
int do_insert(std::pair<K, T> &&rvalue, const Hasher::hash_t &hash)
545543
{
546544
if (hashtable.empty()) {
547-
auto key = rvalue.first;
548545
entries.emplace_back(std::forward<std::pair<K, T>>(rvalue), -1);
549546
do_rehash();
550-
hash = do_hash(key);
551547
} else {
552548
entries.emplace_back(std::forward<std::pair<K, T>>(rvalue), hashtable[hash]);
553549
hashtable[hash] = entries.size() - 1;

0 commit comments

Comments
 (0)