From 7502a9e6f575dae0fa944b67ec19e60191f31b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Mon, 21 May 2018 16:11:34 +0200 Subject: [PATCH] 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 Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#23350} --- rtc_base/basictypes.h | 8 -------- rtc_base/stream.cc | 22 +++++++++------------- rtc_base/stream.h | 3 --- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/rtc_base/basictypes.h b/rtc_base/basictypes.h index 42226e79b2..01ba5ef0e3 100644 --- a/rtc_base/basictypes.h +++ b/rtc_base/basictypes.h @@ -52,14 +52,6 @@ typedef int socklen_t; // The following only works for C++ #ifdef __cplusplus -#ifndef ALIGNP -#define ALIGNP(p, t) \ - (reinterpret_cast(((reinterpret_cast(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) \ diff --git a/rtc_base/stream.cc b/rtc_base/stream.cc index 3a96874dea..9a33e7d533 100644 --- a/rtc_base/stream.cc +++ b/rtc_base/stream.cc @@ -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(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( - 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; diff --git a/rtc_base/stream.h b/rtc_base/stream.h index 77e4bd8a4b..e39141dc09 100644 --- a/rtc_base/stream.h +++ b/rtc_base/stream.h @@ -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