masaori335 commented on a change in pull request #6241:
URL: https://github.com/apache/trafficserver/pull/6241#discussion_r585247843



##########
File path: iocore/eventsystem/I_ProxyAllocator.h
##########
@@ -45,84 +48,49 @@ struct ProxyAllocator {
   ProxyAllocator() {}
 };
 
-template <class C>
-inline C *
-thread_alloc(ClassAllocator<C> &a, ProxyAllocator &l)
+template <class CAlloc, typename... Args>
+typename CAlloc::Value_type *
+thread_alloc(CAlloc &a, ProxyAllocator &l, Args &&... args)
 {
   if (!cmd_disable_pfreelist && l.freelist) {
-    C *v       = (C *)l.freelist;
-    l.freelist = *(C **)l.freelist;
+    void *v    = l.freelist;
+    l.freelist = *reinterpret_cast<void **>(l.freelist);
     --(l.allocated);
-    *(void **)v = *(void **)&a.proto.typeObject;
-    return v;
+    ::new (v) typename CAlloc::Value_type(std::forward<Args>(args)...);
+    return static_cast<typename CAlloc::Value_type *>(v);
   }
-  return a.alloc();
+  return a.alloc(std::forward<Args>(args)...);
 }
 
-template <class C>
-inline C *
-thread_alloc_init(ClassAllocator<C> &a, ProxyAllocator &l)
-{
-  if (!cmd_disable_pfreelist && l.freelist) {
-    C *v       = (C *)l.freelist;
-    l.freelist = *(C **)l.freelist;
-    --(l.allocated);
-    memcpy((void *)v, (void *)&a.proto.typeObject, sizeof(C));
-    return v;
-  }
-  return a.alloc();
-}
+void *thread_alloc(Allocator &a, ProxyAllocator &l);

Review comment:
       Bit off-topic, but could you include `tscore/Allocator.h` or add the 
forward declaration of `Allocator`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to