Commit 04d6ac76 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

cut EventBaseLocal::emplace overload taking pointer

Summary: Cut the `EventBaseLocal::emplace` overload taking a pointer since it is unused and to consolidate on the approach of not letting internals leak.

Differential Revision: D26246689

fbshipit-source-id: 0d9dc1bfcc3d37dc980142b221ee4443b98205a3
parent 0f4db9c7
......@@ -79,11 +79,6 @@ class EventBaseLocal : public detail::EventBaseLocalBase {
T* get(EventBase& evb) { return static_cast<T*>(getVoid(evb)); }
void emplace(EventBase& evb, T* ptr) {
DCHECK(ptr != nullptr);
setVoid(evb, ptr, detail::thunk::ruin<T>);
}
template <typename... Args>
T& emplace(EventBase& evb, Args&&... args) {
auto ptr = new T(static_cast<Args&&>(args)...);
......
......@@ -36,18 +36,18 @@ TEST(EventBaseLocalTest, Basic) {
EXPECT_EQ(foo.get(evb1), nullptr);
foo.emplace(evb1, new Foo(5, [&]() { ++dtorCnt; }));
foo.emplace(evb1, 5, [&] { ++dtorCnt; });
EXPECT_EQ(foo.get(evb1)->n, 5);
{
folly::EventBase evb2;
foo.emplace(evb2, new Foo(6, [&]() { ++dtorCnt; }));
foo.emplace(evb2, 6, [&] { ++dtorCnt; });
EXPECT_EQ(foo.get(evb2)->n, 6);
foo.erase(evb2);
EXPECT_EQ(dtorCnt, 1); // should dtor a Foo when we erase
EXPECT_EQ(foo.get(evb2), nullptr);
foo.emplace(evb2, 7, [&]() { ++dtorCnt; });
foo.emplace(evb2, 7, [&] { ++dtorCnt; });
EXPECT_EQ(foo.get(evb2)->n, 7);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment