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

folly: iterator classes (3/3): IOBuf's custom iterator should use new Iterator detail classes

Summary: IOBuf's custom iterator was changed so that it would no longer need `<boost/iterator_facade.hpp>`.  Change again so that it uses Folly's own (cheap) header file providing roughly the same functionality.

Reviewed By: yfeldblum

Differential Revision: D8345072

fbshipit-source-id: bbbfb4373e72444a5e54aeccafd2d316ebdbae63
parent 46dd483d
......@@ -31,6 +31,7 @@
#include <folly/FBVector.h>
#include <folly/Portability.h>
#include <folly/Range.h>
#include <folly/detail/Iterators.h>
#include <folly/lang/Ordering.h>
#include <folly/portability/SysUio.h>
......@@ -1552,13 +1553,9 @@ inline std::unique_ptr<IOBuf> IOBuf::maybeCopyBuffer(
return copyBuffer(buf.data(), buf.size(), headroom, minTailroom);
}
class IOBuf::Iterator {
class IOBuf::Iterator
: public detail::IteratorFacade<IOBuf::Iterator, ByteRange const> {
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,
// so pos == end is ambiguous (it may mean "begin" or "end"). To solve
......@@ -1585,31 +1582,20 @@ class IOBuf::Iterator {
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();
const ByteRange& dereference() const {
return val_;
}
bool operator==(Iterator const& rhs) const {
return equal(rhs);
bool equal(const Iterator& other) const {
// We must compare end_ in addition to pos_, because forward traversal
// requires that if two iterators are equal (a == b) and dereferenceable,
// then ++a == ++b.
return pos_ == other.pos_ && end_ == other.end_;
}
bool operator!=(Iterator const& rhs) const {
return !equal(rhs);
void increment() {
pos_ = pos_->next();
adjustForEnd();
}
private:
......@@ -1626,22 +1612,6 @@ class IOBuf::Iterator {
}
}
const ByteRange& dereference() const {
return val_;
}
bool equal(const Iterator& other) const {
// We must compare end_ in addition to pos_, because forward traversal
// requires that if two iterators are equal (a == b) and dereferenceable,
// then ++a == ++b.
return pos_ == other.pos_ && end_ == other.end_;
}
void increment() {
pos_ = pos_->next();
adjustForEnd();
}
const IOBuf* pos_{nullptr};
const IOBuf* end_{nullptr};
ByteRange val_;
......
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