Commit 9885dc08 authored by Steve O'Brien's avatar Steve O'Brien Committed by Facebook Github Bot

folly/IOBuf: remove expensive boost header + implement iterator

Reviewed By: yfeldblum

Differential Revision: D7272553

fbshipit-source-id: f0aaa278e6a81a53f78ae29b68f1bf9f1ba02899
parent 2f9ee5b8
...@@ -22,12 +22,11 @@ ...@@ -22,12 +22,11 @@
#include <cinttypes> #include <cinttypes>
#include <cstddef> #include <cstddef>
#include <cstring> #include <cstring>
#include <iterator>
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
#include <boost/iterator/iterator_facade.hpp>
#include <folly/FBString.h> #include <folly/FBString.h>
#include <folly/FBVector.h> #include <folly/FBVector.h>
#include <folly/Portability.h> #include <folly/Portability.h>
...@@ -1479,13 +1478,14 @@ inline std::unique_ptr<IOBuf> IOBuf::maybeCopyBuffer(const std::string& buf, ...@@ -1479,13 +1478,14 @@ inline std::unique_ptr<IOBuf> IOBuf::maybeCopyBuffer(const std::string& buf,
return copyBuffer(buf.data(), buf.size(), headroom, minTailroom); return copyBuffer(buf.data(), buf.size(), headroom, minTailroom);
} }
class IOBuf::Iterator : public boost::iterator_facade< class IOBuf::Iterator {
IOBuf::Iterator, // Derived
const ByteRange, // Value
boost::forward_traversal_tag // Category or traversal
> {
friend class boost::iterator_core_access;
public: public:
using difference_type = ssize_t;
using value_type = ByteRange;
using reference = ByteRange const&;
using pointer = ByteRange const*;
using iterator_category = std::forward_iterator_tag;
// Note that IOBufs are stored as a circular list without a guard node, // Note that IOBufs are stored as a circular list without a guard node,
// so pos == end is ambiguous (it may mean "begin" or "end"). To solve // so pos == end is ambiguous (it may mean "begin" or "end"). To solve
// the ambiguity (at the cost of one extra comparison in the "increment" // the ambiguity (at the cost of one extra comparison in the "increment"
...@@ -1502,6 +1502,44 @@ class IOBuf::Iterator : public boost::iterator_facade< ...@@ -1502,6 +1502,44 @@ class IOBuf::Iterator : public boost::iterator_facade<
Iterator() {} Iterator() {}
Iterator(Iterator const& rhs) : Iterator(rhs.pos_, rhs.end_) {}
Iterator& operator=(Iterator const& rhs) {
pos_ = rhs.pos_;
end_ = rhs.end_;
if (pos_) {
setVal();
}
return *this;
}
Iterator& operator++() {
increment();
return *this;
}
Iterator operator++(int) {
Iterator ret(*this);
++*this;
return ret;
}
ByteRange const& operator*() const {
return dereference();
}
ByteRange const* operator->() const {
return &dereference();
}
bool operator==(Iterator const& rhs) const {
return equal(rhs);
}
bool operator!=(Iterator const& rhs) const {
return !equal(rhs);
}
private: private:
void setVal() { void setVal() {
val_ = ByteRange(pos_->data(), pos_->tail()); val_ = ByteRange(pos_->data(), pos_->tail());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment