From 42d5b05f5465fa705e946d75662e1155030df6ed Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 21 Jul 2023 13:34:13 +0200 Subject: [PATCH] util/IntrusiveHashSet: rename insert() to insert_commit() Clarify that the method is not a freestanding insertion method but should only be used after insert_check(). --- src/RemoteTagCache.cxx | 2 +- src/util/IntrusiveHashSet.hxx | 2 +- test/util/TestIntrusiveHashSet.cxx | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RemoteTagCache.cxx b/src/RemoteTagCache.cxx index f51263347..362683445 100644 --- a/src/RemoteTagCache.cxx +++ b/src/RemoteTagCache.cxx @@ -31,7 +31,7 @@ RemoteTagCache::Lookup(const std::string &uri) noexcept auto [tag, value] = map.insert_check(uri); if (value) { auto item = new Item(*this, uri); - map.insert(tag, *item); + map.insert_commit(tag, *item); waiting_list.push_back(*item); lock.unlock(); diff --git a/src/util/IntrusiveHashSet.hxx b/src/util/IntrusiveHashSet.hxx index 27f0dd718..0cfd63635 100644 --- a/src/util/IntrusiveHashSet.hxx +++ b/src/util/IntrusiveHashSet.hxx @@ -235,7 +235,7 @@ public: * * @param bucket the bucket returned by insert_check() */ - constexpr void insert(bucket_iterator bucket, reference item) noexcept { + constexpr void insert_commit(bucket_iterator bucket, reference item) noexcept { ++counter; GetBucket(item).insert(bucket, item); } diff --git a/test/util/TestIntrusiveHashSet.cxx b/test/util/TestIntrusiveHashSet.cxx index a4b625fd6..bb3b2fc7e 100644 --- a/test/util/TestIntrusiveHashSet.cxx +++ b/test/util/TestIntrusiveHashSet.cxx @@ -43,7 +43,7 @@ TEST(IntrusiveHashSet, Basic) { auto [position, inserted] = set.insert_check(2); ASSERT_TRUE(inserted); - set.insert(position, b); + set.insert_commit(position, b); } ASSERT_FALSE(set.insert_check(2).second); @@ -52,7 +52,7 @@ TEST(IntrusiveHashSet, Basic) { auto [position, inserted] = set.insert_check(a); ASSERT_TRUE(inserted); - set.insert(position, a); + set.insert_commit(position, a); } set.insert(c); @@ -100,7 +100,7 @@ TEST(IntrusiveHashSet, Basic) { auto [position, inserted] = set.insert_check(f); ASSERT_TRUE(inserted); - set.insert(position, f); + set.insert_commit(position, f); } ASSERT_EQ(set.find(a), set.iterator_to(f));