Title: [237460] trunk/Source/WebKit
- Revision
- 237460
- Author
- [email protected]
- Date
- 2018-10-26 08:34:18 -0700 (Fri, 26 Oct 2018)
Log Message
Modernize / Simplify IPC::Connection::sendOutgoingMessage()
https://bugs.webkit.org/show_bug.cgi?id=190931
Reviewed by Alex Christensen.
* Platform/IPC/mac/ConnectionMac.mm:
(IPC::Connection::sendOutgoingMessage):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (237459 => 237460)
--- trunk/Source/WebKit/ChangeLog 2018-10-26 15:29:11 UTC (rev 237459)
+++ trunk/Source/WebKit/ChangeLog 2018-10-26 15:34:18 UTC (rev 237460)
@@ -1,3 +1,13 @@
+2018-10-26 Chris Dumez <[email protected]>
+
+ Modernize / Simplify IPC::Connection::sendOutgoingMessage()
+ https://bugs.webkit.org/show_bug.cgi?id=190931
+
+ Reviewed by Alex Christensen.
+
+ * Platform/IPC/mac/ConnectionMac.mm:
+ (IPC::Connection::sendOutgoingMessage):
+
2018-10-26 Jer Noble <[email protected]>
Adopt -setOverrideRouteSharingPolicy:routingContextUID: SPI
Modified: trunk/Source/WebKit/Platform/IPC/mac/ConnectionMac.mm (237459 => 237460)
--- trunk/Source/WebKit/Platform/IPC/mac/ConnectionMac.mm 2018-10-26 15:29:11 UTC (rev 237459)
+++ trunk/Source/WebKit/Platform/IPC/mac/ConnectionMac.mm 2018-10-26 15:34:18 UTC (rev 237460)
@@ -297,84 +297,63 @@
{
ASSERT(!m_pendingOutgoingMachMessage && !m_isInitializingSendSource);
- Vector<Attachment> attachments = encoder->releaseAttachments();
+ auto attachments = encoder->releaseAttachments();
- size_t numberOfPortDescriptors = 0;
- size_t numberOfOOLMemoryDescriptors = 0;
- for (size_t i = 0; i < attachments.size(); ++i) {
- Attachment::Type type = attachments[i].type();
- if (type == Attachment::MachPortType)
- numberOfPortDescriptors++;
- }
-
- size_t messageSize = MachMessage::messageSize(encoder->bufferSize(), numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
-
+ auto numberOfPortDescriptors = std::count_if(attachments.begin(), attachments.end(), [](auto& attachment) { return attachment.type() == Attachment::MachPortType; });
bool messageBodyIsOOL = false;
+ auto messageSize = MachMessage::messageSize(encoder->bufferSize(), numberOfPortDescriptors, messageBodyIsOOL);
if (messageSize > inlineMessageMaxSize) {
messageBodyIsOOL = true;
-
- numberOfOOLMemoryDescriptors++;
- messageSize = MachMessage::messageSize(0, numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
+ messageSize = MachMessage::messageSize(0, numberOfPortDescriptors, messageBodyIsOOL);
}
auto message = MachMessage::create(messageSize);
-
message->setMessageReceiverName(encoder->messageReceiverName().toString());
message->setMessageName(encoder->messageName().toString());
- bool isComplex = (numberOfPortDescriptors + numberOfOOLMemoryDescriptors) > 0;
-
- mach_msg_header_t* header = message->header();
+ auto* header = message->header();
header->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
header->msgh_size = messageSize;
header->msgh_remote_port = m_sendPort;
header->msgh_local_port = MACH_PORT_NULL;
header->msgh_id = 0;
- if (messageBodyIsOOL)
- header->msgh_id |= MessageBodyIsOutOfLine;
- uint8_t* messageData;
+ auto* messageData = reinterpret_cast<uint8_t*>(header + 1);
+ bool isComplex = numberOfPortDescriptors || messageBodyIsOOL;
if (isComplex) {
header->msgh_bits |= MACH_MSGH_BITS_COMPLEX;
- mach_msg_body_t* body = reinterpret_cast<mach_msg_body_t*>(header + 1);
- body->msgh_descriptor_count = numberOfPortDescriptors + numberOfOOLMemoryDescriptors;
- uint8_t* descriptorData = reinterpret_cast<uint8_t*>(body + 1);
+ auto* body = reinterpret_cast<mach_msg_body_t*>(messageData);
+ body->msgh_descriptor_count = numberOfPortDescriptors + messageBodyIsOOL;
+ messageData = reinterpret_cast<uint8_t*>(body + 1);
- for (size_t i = 0; i < attachments.size(); ++i) {
- Attachment attachment = attachments[i];
+ auto getDescriptorAndSkip = [](uint8_t*& data) {
+ return reinterpret_cast<mach_msg_descriptor_t*>(std::exchange(data, data + sizeof(mach_msg_port_descriptor_t)));
+ };
- mach_msg_descriptor_t* descriptor = reinterpret_cast<mach_msg_descriptor_t*>(descriptorData);
- switch (attachment.type()) {
- case Attachment::MachPortType:
+ for (auto& attachment : attachments) {
+ ASSERT(attachment.type() == Attachment::MachPortType);
+ if (attachment.type() == Attachment::MachPortType) {
+ auto* descriptor = getDescriptorAndSkip(messageData);
descriptor->port.name = attachment.port();
descriptor->port.disposition = attachment.disposition();
- descriptor->port.type = MACH_MSG_PORT_DESCRIPTOR;
-
- descriptorData += sizeof(mach_msg_port_descriptor_t);
- break;
- default:
- ASSERT_NOT_REACHED();
+ descriptor->port.type = MACH_MSG_PORT_DESCRIPTOR;
}
}
if (messageBodyIsOOL) {
- mach_msg_descriptor_t* descriptor = reinterpret_cast<mach_msg_descriptor_t*>(descriptorData);
+ header->msgh_id |= MessageBodyIsOutOfLine;
+ auto* descriptor = getDescriptorAndSkip(messageData);
descriptor->out_of_line.address = encoder->buffer();
descriptor->out_of_line.size = encoder->bufferSize();
descriptor->out_of_line.copy = MACH_MSG_VIRTUAL_COPY;
descriptor->out_of_line.deallocate = false;
descriptor->out_of_line.type = MACH_MSG_OOL_DESCRIPTOR;
-
- descriptorData += sizeof(mach_msg_ool_descriptor_t);
}
+ }
- messageData = descriptorData;
- } else
- messageData = (uint8_t*)(header + 1);
-
// Copy the data if it is not being sent out-of-line.
if (!messageBodyIsOOL)
memcpy(messageData, encoder->buffer(), encoder->bufferSize());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes