mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1092010 - part 1 - add move semantics to Pickle and IPC::Message; r=dvander
This commit is contained in:
parent
264ce0a17d
commit
4fd613ce7d
@ -144,6 +144,16 @@ Pickle::Pickle(const Pickle& other)
|
||||
memcpy(header_, other.header_, payload_size);
|
||||
}
|
||||
|
||||
Pickle::Pickle(Pickle&& other)
|
||||
: header_(other.header_),
|
||||
header_size_(other.header_size_),
|
||||
capacity_(other.capacity_),
|
||||
variable_buffer_offset_(other.variable_buffer_offset_) {
|
||||
other.header_ = NULL;
|
||||
other.capacity_ = 0;
|
||||
other.variable_buffer_offset_ = 0;
|
||||
}
|
||||
|
||||
Pickle::~Pickle() {
|
||||
if (capacity_ != kCapacityReadOnly)
|
||||
free(header_);
|
||||
@ -164,6 +174,14 @@ Pickle& Pickle::operator=(const Pickle& other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Pickle& Pickle::operator=(Pickle&& other) {
|
||||
std::swap(header_, other.header_);
|
||||
std::swap(header_size_, other.header_size_);
|
||||
std::swap(capacity_, other.capacity_);
|
||||
std::swap(variable_buffer_offset_, other.variable_buffer_offset_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Pickle::ReadBool(void** iter, bool* result) const {
|
||||
DCHECK(iter);
|
||||
|
||||
|
@ -49,9 +49,13 @@ class Pickle {
|
||||
// Initializes a Pickle as a deep copy of another Pickle.
|
||||
Pickle(const Pickle& other);
|
||||
|
||||
Pickle(Pickle&& other);
|
||||
|
||||
// Performs a deep copy.
|
||||
Pickle& operator=(const Pickle& other);
|
||||
|
||||
Pickle& operator=(Pickle&& other);
|
||||
|
||||
// Returns the size of the Pickle's data.
|
||||
int size() const { return static_cast<int>(header_size_ +
|
||||
header_->payload_size); }
|
||||
|
@ -14,6 +14,8 @@
|
||||
#include "GeckoTaskTracer.h"
|
||||
#endif
|
||||
|
||||
#include "mozilla/Move.h"
|
||||
|
||||
#ifdef MOZ_TASK_TRACER
|
||||
using namespace mozilla::tasktracer;
|
||||
#endif
|
||||
@ -80,6 +82,18 @@ Message::Message(const Message& other) : Pickle(other) {
|
||||
#endif
|
||||
}
|
||||
|
||||
Message::Message(Message&& other) : Pickle(mozilla::Move(other)) {
|
||||
InitLoggingVariables(other.name_);
|
||||
#if defined(OS_POSIX)
|
||||
file_descriptor_set_ = other.file_descriptor_set_.forget();
|
||||
#endif
|
||||
#ifdef MOZ_TASK_TRACER
|
||||
header()->source_event_id = other.header()->source_event_id;
|
||||
header()->parent_task_id = other.header()->parent_task_id;
|
||||
header()->source_event_type = other.header()->source_event_type;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Message::InitLoggingVariables(const char* const name) {
|
||||
name_ = name;
|
||||
#ifdef IPC_MESSAGE_LOG_ENABLED
|
||||
@ -103,6 +117,20 @@ Message& Message::operator=(const Message& other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Message& Message::operator=(Message&& other) {
|
||||
*static_cast<Pickle*>(this) = mozilla::Move(other);
|
||||
InitLoggingVariables(other.name_);
|
||||
#if defined(OS_POSIX)
|
||||
file_descriptor_set_.swap(other.file_descriptor_set_);
|
||||
#endif
|
||||
#ifdef MOZ_TASK_TRACER
|
||||
std::swap(header()->source_event_id, other.header()->source_event_id);
|
||||
std::swap(header()->parent_task_id, other.header()->parent_task_id);
|
||||
std::swap(header()->source_event_type, other.header()->source_event_type);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef IPC_MESSAGE_LOG_ENABLED
|
||||
void Message::set_sent_time(int64_t time) {
|
||||
DCHECK((header()->flags & HAS_SENT_TIME_BIT) == 0);
|
||||
|
@ -79,7 +79,9 @@ class Message : public Pickle {
|
||||
Message(const char* data, int data_len);
|
||||
|
||||
Message(const Message& other);
|
||||
Message(Message&& other);
|
||||
Message& operator=(const Message& other);
|
||||
Message& operator=(Message&& other);
|
||||
|
||||
PriorityValue priority() const {
|
||||
return static_cast<PriorityValue>(header()->flags & PRIORITY_MASK);
|
||||
|
Loading…
Reference in New Issue
Block a user