This repository was archived by the owner on Oct 28, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,14 +84,20 @@ RLP RLP::operator[](size_t _i) const
8484{
8585 if (_i < m_lastIndex)
8686 {
87+ // Get size of 0th item
8788 m_lastEnd = sizeAsEncoded (payload ());
89+ // Set m_lastItem to 0th item data
8890 m_lastItem = payload ().cropped (0 , m_lastEnd);
8991 m_lastIndex = 0 ;
9092 }
9193 for (; m_lastIndex < _i && m_lastItem.size (); ++m_lastIndex)
9294 {
95+ // Get chunk of payload data starting right after m_lastItem
96+ // This will be empty when we're out of bounds
9397 m_lastItem = payload ().cropped (m_lastEnd);
98+ // Crop it to get the data of the next item
9499 m_lastItem = m_lastItem.cropped (0 , sizeAsEncoded (m_lastItem));
100+ // Point m_lastEnd to next item
95101 m_lastEnd += m_lastItem.size ();
96102 }
97103 return RLP (m_lastItem, ThrowOnFail | FailIfTooSmall);
Original file line number Diff line number Diff line change @@ -340,8 +340,11 @@ class RLP
340340 bytesConstRef m_data;
341341
342342 // / The list-indexing cache.
343+ // Index of the last item accessed with operator[]
343344 mutable size_t m_lastIndex = (size_t )-1 ;
345+ // Offset of the next byte after last byte of m_lastItem
344346 mutable size_t m_lastEnd = 0 ;
347+ // Data of the last item accessed with operator[]
345348 mutable bytesConstRef m_lastItem;
346349};
347350
You can’t perform that action at this time.
0 commit comments