зеркало из https://github.com/mozilla/gecko-dev.git
Bug 871596 - part 2 - add a new memberAlignmentType to replace the scattered uint32_t alignments; r=bent
This commit is contained in:
Родитель
46164cd78e
Коммит
1a69354879
|
@ -19,7 +19,7 @@ static const uint32_t kCapacityReadOnly = (uint32_t) -1;
|
|||
|
||||
static const char kBytePaddingMarker = char(0xbf);
|
||||
|
||||
// Payload is uint32_t aligned.
|
||||
// Payload is sizeof(Pickle::memberAlignmentType) aligned.
|
||||
|
||||
Pickle::Pickle()
|
||||
: header_(NULL),
|
||||
|
@ -35,7 +35,7 @@ Pickle::Pickle(int header_size)
|
|||
header_size_(AlignInt(header_size)),
|
||||
capacity_(0),
|
||||
variable_buffer_offset_(0) {
|
||||
DCHECK(static_cast<uint32_t>(header_size) >= sizeof(Header));
|
||||
DCHECK(static_cast<memberAlignmentType>(header_size) >= sizeof(Header));
|
||||
DCHECK(header_size <= kPayloadUnit);
|
||||
Resize(kPayloadUnit);
|
||||
header_->payload_size = 0;
|
||||
|
@ -441,8 +441,9 @@ char* Pickle::BeginWrite(uint32_t length, uint32_t alignment) {
|
|||
void Pickle::EndWrite(char* dest, int length) {
|
||||
// Zero-pad to keep tools like purify from complaining about uninitialized
|
||||
// memory.
|
||||
if (length % sizeof(uint32_t))
|
||||
memset(dest + length, 0, sizeof(uint32_t) - (length % sizeof(uint32_t)));
|
||||
if (length % sizeof(memberAlignmentType))
|
||||
memset(dest + length, 0,
|
||||
sizeof(memberAlignmentType) - (length % sizeof(memberAlignmentType)));
|
||||
}
|
||||
|
||||
bool Pickle::WriteBytes(const void* data, int data_len, uint32_t alignment) {
|
||||
|
@ -494,7 +495,7 @@ char* Pickle::BeginWriteData(int length) {
|
|||
if (!WriteInt(length))
|
||||
return NULL;
|
||||
|
||||
char *data_ptr = BeginWrite(length, sizeof(uint32_t));
|
||||
char *data_ptr = BeginWrite(length, sizeof(memberAlignmentType));
|
||||
if (!data_ptr)
|
||||
return NULL;
|
||||
|
||||
|
@ -541,7 +542,7 @@ const char* Pickle::FindNext(uint32_t header_size,
|
|||
const char* start,
|
||||
const char* end) {
|
||||
DCHECK(header_size == AlignInt(header_size));
|
||||
DCHECK(header_size <= static_cast<uint32_t>(kPayloadUnit));
|
||||
DCHECK(header_size <= static_cast<memberAlignmentType>(kPayloadUnit));
|
||||
|
||||
const Header* hdr = reinterpret_cast<const Header*>(start);
|
||||
const char* payload_base = start + header_size;
|
||||
|
|
|
@ -84,7 +84,7 @@ class Pickle {
|
|||
bool ReadString16(void** iter, string16* result) const;
|
||||
bool ReadData(void** iter, const char** data, int* length) const;
|
||||
bool ReadBytes(void** iter, const char** data, int length,
|
||||
uint32_t alignment = sizeof(uint32_t)) const;
|
||||
uint32_t alignment = sizeof(memberAlignmentType)) const;
|
||||
|
||||
// Safer version of ReadInt() checks for the result not being negative.
|
||||
// Use it for reading the object sizes.
|
||||
|
@ -149,7 +149,7 @@ class Pickle {
|
|||
bool WriteString16(const string16& value);
|
||||
bool WriteData(const char* data, int length);
|
||||
bool WriteBytes(const void* data, int data_len,
|
||||
uint32_t alignment = sizeof(uint32_t));
|
||||
uint32_t alignment = sizeof(memberAlignmentType));
|
||||
|
||||
// Same as WriteData, but allows the caller to write directly into the
|
||||
// Pickle. This saves a copy in cases where the data is not already
|
||||
|
@ -206,6 +206,8 @@ class Pickle {
|
|||
return (iter <= end_of_region) && (end_of_region <= end_of_payload());
|
||||
}
|
||||
|
||||
typedef uint32_t memberAlignmentType;
|
||||
|
||||
protected:
|
||||
uint32_t payload_size() const { return header_->payload_size; }
|
||||
|
||||
|
@ -257,12 +259,12 @@ class Pickle {
|
|||
};
|
||||
|
||||
static uint32_t AlignInt(int bytes) {
|
||||
return ConstantAligner<sizeof(uint32_t)>::align(bytes);
|
||||
return ConstantAligner<sizeof(memberAlignmentType)>::align(bytes);
|
||||
}
|
||||
|
||||
// Moves the iterator by the given number of bytes, making sure it is aligned.
|
||||
// Pointer (iterator) is NOT aligned, but the change in the pointer
|
||||
// is guaranteed to be a multiple of sizeof(uint32_t).
|
||||
// is guaranteed to be a multiple of sizeof(memberAlignmentType).
|
||||
static void UpdateIter(void** iter, int bytes) {
|
||||
*iter = static_cast<char*>(*iter) + AlignInt(bytes);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче