minor SharedBuffer clean-up
Change-Id: If38b7ce85806ae628c00f2c938de4e3f75142543
This commit is contained in:
parent
2401ead700
commit
50f262fe56
@ -45,9 +45,6 @@ public:
|
||||
*/
|
||||
static ssize_t dealloc(const SharedBuffer* released);
|
||||
|
||||
//! get the SharedBuffer from the data pointer
|
||||
static inline const SharedBuffer* sharedBuffer(const void* data);
|
||||
|
||||
//! access the data for read
|
||||
inline const void* data() const;
|
||||
|
||||
@ -94,7 +91,8 @@ public:
|
||||
private:
|
||||
inline SharedBuffer() { }
|
||||
inline ~SharedBuffer() { }
|
||||
inline SharedBuffer(const SharedBuffer&);
|
||||
SharedBuffer(const SharedBuffer&);
|
||||
SharedBuffer& operator = (const SharedBuffer&);
|
||||
|
||||
// 16 bytes. must be sized to preserve correct alignment.
|
||||
mutable int32_t mRefs;
|
||||
@ -104,10 +102,6 @@ private:
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const SharedBuffer* SharedBuffer::sharedBuffer(const void* data) {
|
||||
return data ? reinterpret_cast<const SharedBuffer *>(data)-1 : 0;
|
||||
}
|
||||
|
||||
const void* SharedBuffer::data() const {
|
||||
return this + 1;
|
||||
}
|
||||
@ -120,19 +114,16 @@ size_t SharedBuffer::size() const {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
SharedBuffer* SharedBuffer::bufferFromData(void* data)
|
||||
{
|
||||
return ((SharedBuffer*)data)-1;
|
||||
SharedBuffer* SharedBuffer::bufferFromData(void* data) {
|
||||
return data ? static_cast<SharedBuffer *>(data)-1 : 0;
|
||||
}
|
||||
|
||||
const SharedBuffer* SharedBuffer::bufferFromData(const void* data)
|
||||
{
|
||||
return ((const SharedBuffer*)data)-1;
|
||||
const SharedBuffer* SharedBuffer::bufferFromData(const void* data) {
|
||||
return data ? static_cast<const SharedBuffer *>(data)-1 : 0;
|
||||
}
|
||||
|
||||
size_t SharedBuffer::sizeFromData(const void* data)
|
||||
{
|
||||
return (((const SharedBuffer*)data)-1)->mSize;
|
||||
size_t SharedBuffer::sizeFromData(const void* data) {
|
||||
return data ? bufferFromData(data)->mSize : 0;
|
||||
}
|
||||
|
||||
bool SharedBuffer::onlyOwner() const {
|
||||
|
@ -51,7 +51,7 @@ VectorImpl::VectorImpl(const VectorImpl& rhs)
|
||||
mFlags(rhs.mFlags), mItemSize(rhs.mItemSize)
|
||||
{
|
||||
if (mStorage) {
|
||||
SharedBuffer::sharedBuffer(mStorage)->acquire();
|
||||
SharedBuffer::bufferFromData(mStorage)->acquire();
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ VectorImpl& VectorImpl::operator = (const VectorImpl& rhs)
|
||||
if (rhs.mCount) {
|
||||
mStorage = rhs.mStorage;
|
||||
mCount = rhs.mCount;
|
||||
SharedBuffer::sharedBuffer(mStorage)->acquire();
|
||||
SharedBuffer::bufferFromData(mStorage)->acquire();
|
||||
} else {
|
||||
mStorage = 0;
|
||||
mCount = 0;
|
||||
@ -85,7 +85,7 @@ VectorImpl& VectorImpl::operator = (const VectorImpl& rhs)
|
||||
void* VectorImpl::editArrayImpl()
|
||||
{
|
||||
if (mStorage) {
|
||||
SharedBuffer* sb = SharedBuffer::sharedBuffer(mStorage)->attemptEdit();
|
||||
SharedBuffer* sb = SharedBuffer::bufferFromData(mStorage)->attemptEdit();
|
||||
if (sb == 0) {
|
||||
sb = SharedBuffer::alloc(capacity() * mItemSize);
|
||||
if (sb) {
|
||||
@ -101,7 +101,7 @@ void* VectorImpl::editArrayImpl()
|
||||
size_t VectorImpl::capacity() const
|
||||
{
|
||||
if (mStorage) {
|
||||
return SharedBuffer::sharedBuffer(mStorage)->size() / mItemSize;
|
||||
return SharedBuffer::bufferFromData(mStorage)->size() / mItemSize;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -346,7 +346,7 @@ ssize_t VectorImpl::setCapacity(size_t new_capacity)
|
||||
void VectorImpl::release_storage()
|
||||
{
|
||||
if (mStorage) {
|
||||
const SharedBuffer* sb = SharedBuffer::sharedBuffer(mStorage);
|
||||
const SharedBuffer* sb = SharedBuffer::bufferFromData(mStorage);
|
||||
if (sb->release(SharedBuffer::eKeepStorage) == 1) {
|
||||
_do_destroy(mStorage, mCount);
|
||||
SharedBuffer::dealloc(sb);
|
||||
@ -372,7 +372,7 @@ void* VectorImpl::_grow(size_t where, size_t amount)
|
||||
(mFlags & HAS_TRIVIAL_COPY) &&
|
||||
(mFlags & HAS_TRIVIAL_DTOR))
|
||||
{
|
||||
const SharedBuffer* cur_sb = SharedBuffer::sharedBuffer(mStorage);
|
||||
const SharedBuffer* cur_sb = SharedBuffer::bufferFromData(mStorage);
|
||||
SharedBuffer* sb = cur_sb->editResize(new_capacity * mItemSize);
|
||||
mStorage = sb->data();
|
||||
} else {
|
||||
@ -424,7 +424,7 @@ void VectorImpl::_shrink(size_t where, size_t amount)
|
||||
(mFlags & HAS_TRIVIAL_COPY) &&
|
||||
(mFlags & HAS_TRIVIAL_DTOR))
|
||||
{
|
||||
const SharedBuffer* cur_sb = SharedBuffer::sharedBuffer(mStorage);
|
||||
const SharedBuffer* cur_sb = SharedBuffer::bufferFromData(mStorage);
|
||||
SharedBuffer* sb = cur_sb->editResize(new_capacity * mItemSize);
|
||||
mStorage = sb->data();
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user