mirror of
https://github.com/ceph/ceph
synced 2024-12-28 14:34:13 +00:00
buffer: add iterator copy_shallow() to ptr
If the length resides within the bufferlist's current ptr, return a ptr to the same buffer. Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
6d7f748653
commit
14cad5655d
@ -1157,6 +1157,22 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
|
||||
dest = create(len);
|
||||
copy(len, dest.c_str());
|
||||
}
|
||||
template<bool is_const>
|
||||
void buffer::list::iterator_impl<is_const>::copy_shallow(unsigned len,
|
||||
ptr &dest)
|
||||
{
|
||||
if (p == ls->end())
|
||||
throw end_of_buffer();
|
||||
assert(p->length() > 0);
|
||||
unsigned howmuch = p->length() - p_off;
|
||||
if (howmuch < len) {
|
||||
dest = create(len);
|
||||
copy(len, dest.c_str());
|
||||
} else {
|
||||
dest = ptr(*p, p_off, len);
|
||||
advance(len);
|
||||
}
|
||||
}
|
||||
|
||||
template<bool is_const>
|
||||
void buffer::list::iterator_impl<is_const>::copy(unsigned len, list &dest)
|
||||
|
@ -321,6 +321,7 @@ namespace buffer CEPH_BUFFER_API {
|
||||
// note that these all _append_ to dest!
|
||||
void copy(unsigned len, char *dest);
|
||||
void copy_deep(unsigned len, ptr &dest);
|
||||
void copy_shallow(unsigned len, ptr &dest);
|
||||
void copy(unsigned len, list &dest);
|
||||
void copy(unsigned len, std::string &dest);
|
||||
void copy_all(list &dest);
|
||||
@ -361,6 +362,7 @@ namespace buffer CEPH_BUFFER_API {
|
||||
// copy data out
|
||||
void copy(unsigned len, char *dest);
|
||||
void copy_deep(unsigned len, ptr &dest);
|
||||
void copy_shallow(unsigned len, ptr &dest);
|
||||
void copy(unsigned len, list &dest);
|
||||
void copy(unsigned len, std::string &dest);
|
||||
void copy_all(list &dest);
|
||||
|
@ -1227,6 +1227,17 @@ TEST(BufferListIterator, copy) {
|
||||
EXPECT_EQ('B', ptr[1]);
|
||||
}
|
||||
//
|
||||
// void buffer::list::iterator::copy_shallow(unsigned len, ptr &dest)
|
||||
//
|
||||
{
|
||||
bufferptr ptr;
|
||||
bufferlist::iterator i(&bl);
|
||||
i.copy_shallow(2, ptr);
|
||||
EXPECT_EQ((unsigned)2, ptr.length());
|
||||
EXPECT_EQ('A', ptr[0]);
|
||||
EXPECT_EQ('B', ptr[1]);
|
||||
}
|
||||
//
|
||||
// void buffer::list::iterator::copy(unsigned len, list &dest)
|
||||
//
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user