@@ -465,6 +465,9 @@ class BlockIter : public InternalIteratorBase<TValue> {
465465 uint32_t restarts_; // Offset of restart array (list of fixed32)
466466 // current_ is offset in data_ of current entry. >= restarts_ if !Valid
467467 uint32_t current_;
468+ // Cached result of GetKeysEndOffset(). Computed once in InitializeBase()
469+ // since values_section_, data_, and restarts_ do not change afterward.
470+ uint32_t keys_end_offset_{0 };
468471 // Raw key from block.
469472 IterKey raw_key_;
470473 // Buffer for key data when global seqno assignment is enabled.
@@ -588,6 +591,9 @@ class BlockIter : public InternalIteratorBase<TValue> {
588591 (block_restart_interval > 0 || num_restarts == 1 )));
589592
590593 values_section_ = values_section;
594+ keys_end_offset_ = values_section_
595+ ? static_cast <uint32_t >(values_section_ - data_)
596+ : restarts_;
591597 current_ = GetKeysEndOffset ();
592598 }
593599
@@ -704,10 +710,7 @@ class BlockIter : public InternalIteratorBase<TValue> {
704710 // Return the offset where the keys section ends.
705711 // For separated KV storage, this is the start of the values section.
706712 // Otherwise, it's the start of the restart array.
707- inline uint32_t GetKeysEndOffset () const {
708- return values_section_ ? static_cast <uint32_t >(values_section_ - data_)
709- : restarts_;
710- }
713+ inline uint32_t GetKeysEndOffset () const { return keys_end_offset_; }
711714
712715 uint32_t GetRestartPoint (uint32_t index) const {
713716 assert (index < num_restarts_);
0 commit comments