-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge ImmediateClosure and DelayedClosure to Closure #2363
Comments
Likely, yes, but TDLib is written in C++14, hence we can't use std::apply and other minor features used in the PoC code. Also, what benefits do you try to achieve by merging the classes? |
td/tdactor/td/actor/impl/Event.h Lines 56 to 98 in 70bee08
int a = 1;
int b = 2;
const Base* obj = new Derive{};
auto c = MakeImmediateClosure(&Derive::add, a, b);
std::cout << "run memptr: " << c.run(obj) << std::endl;
delete obj;
auto c2 = MakeImmediateClosure([](int a, int b) { return a + b + 4; }, a, b);
std::cout << "run lambda: " << c2.run(obj) << std::endl; // or c2.run(), obj is ignored. |
It is definitely possible to achieve the same behavior in many ways. But is there reason to change the current implementation? |
It is for simplify logic code, and usage consistency for lambda and member pointer function only. In addition, the events that send to actor is mostly custom events (i.e. member pointer functor), it can improve performance like _FunAlloc __af(__a);
if (__use_small_storage<_Fun>())
{
::new ((void*)&__buf_.__small)
_Fun(_VSTD::move(__f), _Alloc(__af));
}
else
{
typedef __allocator_destructor<_FunAlloc> _Dp;
unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
::new ((void*)__hold.get())
_Fun(_VSTD::move(__f), _Alloc(__af));
__buf_.__large = __hold.release();
} |
td/tdutils/td/utils/Closure.h
Lines 56 to 118 in 70bee08
It seems
ImmediateClosure
andDelayedClosure
can merge to one class, for example (see Insights):The text was updated successfully, but these errors were encountered: