diff --git a/include/dwarfs/byte_buffer.h b/include/dwarfs/byte_buffer.h index 96c4fa73..d8463771 100644 --- a/include/dwarfs/byte_buffer.h +++ b/include/dwarfs/byte_buffer.h @@ -67,6 +67,8 @@ class mutable_byte_buffer_interface : public byte_buffer_interface { class shared_byte_buffer { public: + using value_type = uint8_t; + shared_byte_buffer() = default; explicit shared_byte_buffer(std::shared_ptr bb) @@ -114,6 +116,8 @@ class shared_byte_buffer { class mutable_byte_buffer { public: + using value_type = uint8_t; + explicit mutable_byte_buffer( std::shared_ptr bb) : bb_{std::move(bb)} {} diff --git a/src/writer/segmenter.cpp b/src/writer/segmenter.cpp index 9d3157b8..d03698b5 100644 --- a/src/writer/segmenter.cpp +++ b/src/writer/segmenter.cpp @@ -507,11 +507,13 @@ using MultiBlockSegmentationPolicy = BasicSegmentationPolicy; template -class granular_vector_adapter : private GranularityPolicy { +class basic_granular_container_adapter : private GranularityPolicy { public: + using value_type = typename T::value_type; + template DWARFS_FORCE_INLINE - granular_vector_adapter(std::vector& v, PolicyArgs&&... args) + basic_granular_container_adapter(T& v, PolicyArgs&&... args) : GranularityPolicy(std::forward(args)...) , v_{v} {} @@ -519,8 +521,8 @@ class granular_vector_adapter : private GranularityPolicy { return this->bytes_to_frames(v_.size()); } - DWARFS_FORCE_INLINE void - append(granular_span_adapter const& span) { + DWARFS_FORCE_INLINE void append( + granular_span_adapter const& span) { auto raw = span.raw(); auto off = v_.size(); v_.resize(off + raw.size()); @@ -529,7 +531,8 @@ class granular_vector_adapter : private GranularityPolicy { DWARFS_FORCE_INLINE int compare(size_t offset, - granular_span_adapter const& span) const { + granular_span_adapter const& + span) const { auto raw = span.raw(); return std::memcmp(v_.data() + this->frames_to_bytes(offset), raw.data(), raw.size()); @@ -537,22 +540,31 @@ class granular_vector_adapter : private GranularityPolicy { template DWARFS_FORCE_INLINE void update_hash(H& hasher, size_t offset) const { - offset = this->frames_to_bytes(offset); - this->for_bytes_in_frame([&] { hasher.update(v_[offset++]); }); + auto p = v_.data() + this->frames_to_bytes(offset); + this->for_bytes_in_frame([&] { hasher.update(*p++); }); } template DWARFS_FORCE_INLINE void update_hash(H& hasher, size_t from, size_t to) const { - from = this->frames_to_bytes(from); - to = this->frames_to_bytes(to); - this->for_bytes_in_frame([&] { hasher.update(v_[from++], v_[to++]); }); + auto const p = v_.data(); + auto pfrom = p + this->frames_to_bytes(from); + auto pto = p + this->frames_to_bytes(to); + this->for_bytes_in_frame([&] { hasher.update(*pfrom++, *pto++); }); } private: - std::vector& v_; + T& v_; }; +template +using granular_vector_adapter = + basic_granular_container_adapter, GranularityPolicy>; + +template +using granular_byte_buffer_adapter = + basic_granular_container_adapter; + template class active_block : private GranularityPolicy { private: @@ -883,6 +895,10 @@ active_block::append_bytes( auto v = this->template create< granular_vector_adapter>(data_.raw_vector()); + // TODO: this works in theory, but slows down the segmenter by almost 10% + // auto v = this->template create< + // granular_byte_buffer_adapter>(data_); + auto offset = v.size(); DWARFS_CHECK(offset + src.size() <= capacity_in_frames_,