Delete ALIGNP macro, and use thereof in MemoryStream.

Deletes the ALIGNP and RTC_ALIGNED_P macros from basictypes.h.

ALIGNP was used by MemoryStream, supposedly to make it more efficient.
If it really provided an efficiency improvement is unclear, and in any
case, MemoryStream is used for tests only, and doesn't need high
performance.

Bug: webrtc:6853
Change-Id: If835e881e3857dcc22c7a544491b92829a81d1b3
Reviewed-on: https://webrtc-review.googlesource.com/78021
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23350}
This commit is contained in:
Niels Möller
2018-05-21 16:11:34 +02:00
committed by Commit Bot
parent 2cf9c55f35
commit 7502a9e6f5
3 changed files with 9 additions and 24 deletions

View File

@ -52,14 +52,6 @@ typedef int socklen_t;
// The following only works for C++
#ifdef __cplusplus
#ifndef ALIGNP
#define ALIGNP(p, t) \
(reinterpret_cast<uint8_t*>(((reinterpret_cast<uintptr_t>(p) + \
((t) - 1)) & ~((t) - 1))))
#endif
#define RTC_IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a) - 1)))
// Use these to declare and define a static local variable that gets leaked so
// that its destructors are not called at exit.
#define RTC_DEFINE_STATIC_LOCAL(type, name, arguments) \

View File

@ -583,26 +583,25 @@ StreamResult MemoryStreamBase::DoReserve(size_t size, int* error) {
///////////////////////////////////////////////////////////////////////////////
MemoryStream::MemoryStream() : buffer_alloc_(nullptr) {}
MemoryStream::MemoryStream(const char* data) : buffer_alloc_(nullptr) {
MemoryStream::MemoryStream() {}
MemoryStream::MemoryStream(const char* data) {
SetData(data, strlen(data));
}
MemoryStream::MemoryStream(const void* data, size_t length)
: buffer_alloc_(nullptr) {
MemoryStream::MemoryStream(const void* data, size_t length) {
SetData(data, length);
}
MemoryStream::~MemoryStream() {
delete [] buffer_alloc_;
delete [] buffer_;
}
void MemoryStream::SetData(const void* data, size_t length) {
data_length_ = buffer_length_ = length;
delete [] buffer_alloc_;
buffer_alloc_ = new char[buffer_length_ + kAlignment];
buffer_ = reinterpret_cast<char*>(ALIGNP(buffer_alloc_, kAlignment));
delete [] buffer_;
buffer_ = new char[buffer_length_];
memcpy(buffer_, data, data_length_);
seek_position_ = 0;
}
@ -611,12 +610,9 @@ StreamResult MemoryStream::DoReserve(size_t size, int* error) {
if (buffer_length_ >= size)
return SR_SUCCESS;
if (char* new_buffer_alloc = new char[size + kAlignment]) {
char* new_buffer = reinterpret_cast<char*>(
ALIGNP(new_buffer_alloc, kAlignment));
if (char* new_buffer = new char[size]) {
memcpy(new_buffer, buffer_, data_length_);
delete [] buffer_alloc_;
buffer_alloc_ = new_buffer_alloc;
delete [] buffer_;
buffer_ = new_buffer;
buffer_length_ = size;
return SR_SUCCESS;

View File

@ -465,9 +465,6 @@ class MemoryStream : public MemoryStreamBase {
protected:
StreamResult DoReserve(size_t size, int* error) override;
// Memory Streams are aligned for efficiency.
static const int kAlignment = 16;
char* buffer_alloc_;
};
// ExternalMemoryStream adapts an external memory buffer, so writes which would