MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / FindByte

Method FindByte

src/streams.h:622–642  ·  view source on GitHub ↗

search for a given byte in the stream, and remain positioned on it

Source from the content-addressed store, hash-verified

620
621 //! search for a given byte in the stream, and remain positioned on it
622 void FindByte(std::byte byte)
623 {
624 // For best performance, avoid mod operation within the loop.
625 size_t buf_offset{size_t(m_read_pos % uint64_t(vchBuf.size()))};
626 while (true) {
627 if (m_read_pos == nSrcPos) {
628 // No more bytes available; read from the file into the buffer,
629 // setting nSrcPos to one beyond the end of the new data.
630 // Throws exception if end-of-file reached.
631 Fill();
632 }
633 const size_t len{std::min<size_t>(vchBuf.size() - buf_offset, nSrcPos - m_read_pos)};
634 const auto it_start{vchBuf.begin() + buf_offset};
635 const auto it_find{std::find(it_start, it_start + len, byte)};
636 const size_t inc{size_t(std::distance(it_start, it_find))};
637 m_read_pos += inc;
638 if (inc < len) break;
639 buf_offset += inc;
640 if (buf_offset >= vchBuf.size()) buf_offset = 0;
641 }
642 }
643};
644
645/**

Callers 4

LoadExternalBlockFileMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
FUZZ_TARGETFunction · 0.80
FindByteFunction · 0.80

Calls 2

sizeMethod · 0.45
beginMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.64
FUZZ_TARGETFunction · 0.64