From: Alberto Gonzalez Date: Mon, 20 Apr 2020 02:16:55 +0000 (+0000) Subject: In `pool`, construct `entry_t`s in-place and add an rvalue-accepting-and-forwarding... X-Git-Tag: working-ls180~598^2~3 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=95b94ad19b025cef0617610a2605f23688a48a2f;p=yosys.git In `pool`, construct `entry_t`s in-place and add an rvalue-accepting-and-forwarding `insert()` method. --- diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 996bda38e..1a21494a7 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -745,11 +745,24 @@ protected: int do_insert(const K &value, int &hash) { if (hashtable.empty()) { - entries.push_back(entry_t(value, -1)); + entries.emplace_back(value, -1); + do_rehash(); + hash = do_hash(value); + } else { + entries.emplace_back(value, hashtable[hash]); + hashtable[hash] = entries.size() - 1; + } + return entries.size() - 1; + } + + int do_insert(K &&value, int &hash) + { + if (hashtable.empty()) { + entries.emplace_back(std::forward(value), -1); do_rehash(); hash = do_hash(value); } else { - entries.push_back(entry_t(value, hashtable[hash])); + entries.emplace_back(std::forward(value), hashtable[hash]); hashtable[hash] = entries.size() - 1; } return entries.size() - 1; @@ -847,6 +860,16 @@ public: return std::pair(iterator(this, i), true); } + std::pair insert(K &&value) + { + int hash = do_hash(value); + int i = do_lookup(value, hash); + if (i >= 0) + return std::pair(iterator(this, i), false); + i = do_insert(std::forward(value), hash); + return std::pair(iterator(this, i), true); + } + int erase(const K &key) { int hash = do_hash(key);