Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer: add advance(unsigned) back #11993

Merged
merged 2 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 4 additions & 18 deletions src/common/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -781,20 +781,6 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
return new raw_unshareable(len);
}

class dummy_raw : public buffer::raw {
public:
dummy_raw()
: raw(UINT_MAX)
{}
virtual raw* clone_empty() override {
return new dummy_raw();
}
};

buffer::raw* buffer::create_dummy() {
return new dummy_raw();
}

buffer::ptr::ptr(raw *r) : _raw(r), _off(0), _len(r->len) // no lock needed; this is an unref raw.
{
r->nref.inc();
Expand Down Expand Up @@ -1096,7 +1082,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
: iterator_impl<is_const>(i.bl, i.off, i.p, i.p_off) {}

template<bool is_const>
void buffer::list::iterator_impl<is_const>::advance(ssize_t o)
void buffer::list::iterator_impl<is_const>::advance(int o)
{
//cout << this << " advance " << o << " from " << off << " (p_off " << p_off << " in " << p->length() << ")" << std::endl;
if (o > 0) {
Expand Down Expand Up @@ -1135,7 +1121,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
}

template<bool is_const>
void buffer::list::iterator_impl<is_const>::seek(size_t o)
void buffer::list::iterator_impl<is_const>::seek(unsigned o)
{
p = ls->begin();
off = p_off = 0;
Expand Down Expand Up @@ -1327,12 +1313,12 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
: iterator_impl(l, o, ip, po)
{}

void buffer::list::iterator::advance(ssize_t o)
void buffer::list::iterator::advance(int o)
{
buffer::list::iterator_impl<false>::advance(o);
}

void buffer::list::iterator::seek(size_t o)
void buffer::list::iterator::seek(unsigned o)
{
buffer::list::iterator_impl<false>::seek(o);
}
Expand Down
9 changes: 4 additions & 5 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ namespace buffer CEPH_BUFFER_API {
raw* create_page_aligned(unsigned len);
raw* create_zero_copy(unsigned len, int fd, int64_t *offset);
raw* create_unshareable(unsigned len);
raw* create_dummy();
raw* create_static(unsigned len, char *buf);
raw* claim_buffer(unsigned len, char *buf, deleter del);

Expand Down Expand Up @@ -391,8 +390,8 @@ namespace buffer CEPH_BUFFER_API {
//return off == bl->length();
}

void advance(ssize_t o);
void seek(size_t o);
void advance(int o);
void seek(unsigned o);
char operator*() const;
iterator_impl& operator++();
ptr get_current_ptr() const;
Expand Down Expand Up @@ -435,8 +434,8 @@ namespace buffer CEPH_BUFFER_API {
iterator(bl_t *l, unsigned o=0);
iterator(bl_t *l, unsigned o, list_iter_t ip, unsigned po);

void advance(ssize_t o);
void seek(size_t o);
void advance(int o);
void seek(unsigned o);
char operator*();
iterator& operator++();
ptr get_current_ptr();
Expand Down
15 changes: 0 additions & 15 deletions src/test/bufferlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1297,21 +1297,6 @@ TEST(BufferListIterator, copy) {
}
}

TEST(BufferListIterator, copy_huge) {
constexpr unsigned len = 2268888894U;
static_assert(int(len) < 0,
"should be a number underflows when being casted to int.");
bufferptr ptr(buffer::create_dummy());
ptr.set_length(len);

bufferlist src, dest;
src.append(ptr);
auto bp = src.begin();
bp.copy(len, dest);
// contents_equal() is not for this test
EXPECT_EQ(len, dest.length());
}

TEST(BufferListIterator, copy_in) {
bufferlist bl;
const char *existing = "XXX";
Expand Down