@@ -8956,58 +8956,82 @@ class BlockBasedTableOptionsJni
89568956 }
89578957};
89588958
8959- struct ReadOptionsWithValue : public ReadOptions {
8960- using ReadOptions::ReadOptions;
8961- // do not copy m_inuse_list & m_zfree_list
8962- ReadOptionsWithValue (const ReadOptionsWithValue& y) : ReadOptions(y) {}
8963- ReadOptionsWithValue& operator =(const ReadOptionsWithValue& y) {
8964- ReadOptions::operator =(y);
8965- // do not copy m_inuse_list & m_zfree_list
8966- return *this ;
8967- }
8968- struct PinnableSliceNode : PinnableSlice {
8969- PinnableSliceNode* next;
8959+ // / requires Object::Reset()
8960+ template <class Object >
8961+ class ObjectPool {
8962+ struct ListNode : Object {
8963+ ListNode* next;
89708964 };
8971- struct PinnableSliceList {
8972- ~PinnableSliceList () {
8965+ struct ListMeta {
8966+ ~ListMeta () {
89738967 for (auto node = m_head; node; ) {
89748968 auto next = node->next ;
89758969 delete node;
89768970 node = next;
89778971 }
89788972 }
8979- PinnableSliceNode * m_head = nullptr ;
8973+ ListNode * m_head = nullptr ;
89808974 size_t m_size = 0 ;
89818975 };
8982- size_t ZeroCopyListLen () const { return m_inuse_list.m_size ; }
8983- auto NewPinnableSlice () const {
8984- if (auto p = m_zfree_list.m_head ) {
8985- m_zfree_list.m_head = p->next ;
8986- m_zfree_list.m_size --;
8987- return std::unique_ptr<PinnableSliceNode>(p);
8988- }
8989- return std::unique_ptr<PinnableSliceNode>(new PinnableSliceNode ());
8990- }
8991- void RegisterZeroCopy (std::unique_ptr<PinnableSliceNode>&& node) const {
8992- node->next = m_inuse_list.m_head ;
8993- m_inuse_list.m_head = node.release ();
8994- m_inuse_list.m_size ++;
8995- }
8996- void ClearZeroCopyList () {
8997- auto pp = &m_inuse_list.m_head ;
8976+ ListMeta m_pinning_list;
8977+ ListMeta m_pooling_list;
8978+ public:
8979+ ~ObjectPool () {
8980+ ROCKSDB_ASSERT_EQ (m_pinning_list.m_size , 0 );
8981+ }
8982+ auto NewObjectUniquePtr () {
8983+ if (auto p = m_pooling_list.m_head ) {
8984+ m_pooling_list.m_head = p->next ;
8985+ m_pooling_list.m_size --;
8986+ return std::unique_ptr<ListNode>(p);
8987+ }
8988+ return std::unique_ptr<ListNode>(new ListNode ());
8989+ }
8990+ void PinObject (std::unique_ptr<ListNode>&& node) {
8991+ node->next = m_pinning_list.m_head ;
8992+ m_pinning_list.m_head = node.release ();
8993+ m_pinning_list.m_size ++;
8994+ }
8995+ void ClearPinningList () {
8996+ auto pp = &m_pinning_list.m_head ;
89988997 while (auto p = *pp)
89998998 p->Reset (), pp = &p->next ;
9000- *pp = m_zfree_list .m_head ;
9001- m_zfree_list .m_head = m_inuse_list .m_head ;
9002- m_zfree_list .m_size += m_inuse_list .m_size ;
9003- new (&m_inuse_list) PinnableSliceList ();
8999+ *pp = m_pooling_list .m_head ;
9000+ m_pooling_list .m_head = m_pinning_list .m_head ;
9001+ m_pooling_list .m_size += m_pinning_list .m_size ;
9002+ new (&m_pinning_list) ListMeta ();
90049003 }
9005- ~ReadOptionsWithValue () {
9006- ROCKSDB_ASSERT_EQ (m_inuse_list.m_size , 0 );
9004+ size_t PinningListLen () const { return m_pinning_list.m_size ; }
9005+ };
9006+
9007+ struct ReadOptionsWithValue : public ReadOptions {
9008+ using ReadOptions::ReadOptions;
9009+ // do not copy m_single_get & m_multi_get
9010+ ReadOptionsWithValue (const ReadOptionsWithValue& y) : ReadOptions(y) {}
9011+ ReadOptionsWithValue& operator =(const ReadOptionsWithValue& y) {
9012+ ReadOptions::operator =(y);
9013+ // do not copy m_single_get & m_multi_get
9014+ return *this ;
90079015 }
9008- private:
9009- mutable PinnableSliceList m_inuse_list;
9010- mutable PinnableSliceList m_zfree_list;
9016+ size_t ZeroCopyListLen () const { return m_single_get.PinningListLen (); }
9017+ auto NewPinnableSlice () {
9018+ return m_single_get.NewObjectUniquePtr ();
9019+ }
9020+ template <class PinnableSliceNode >
9021+ void RegisterZeroCopy (std::unique_ptr<PinnableSliceNode>&& node) {
9022+ m_single_get.PinObject (std::move (node));
9023+ }
9024+ void ClearZeroCopyList () {
9025+ m_single_get.ClearPinningList ();
9026+ }
9027+ struct MultiGetVector : std::vector<PinnableSlice> {
9028+ void Reset () {
9029+ for (PinnableSlice& x : *this )
9030+ x.Reset ();
9031+ }
9032+ };
9033+ ObjectPool<PinnableSlice> m_single_get;
9034+ ObjectPool<MultiGetVector> m_multi_get;
90119035};
90129036
90139037} // namespace ROCKSDB_NAMESPACE
0 commit comments