Title: [285866] trunk/Source/WebKit
- Revision
- 285866
- Author
- [email protected]
- Date
- 2021-11-16 08:57:55 -0800 (Tue, 16 Nov 2021)
Log Message
Decoder::unwrapForTesting() is unnecessarily inefficient
https://bugs.webkit.org/show_bug.cgi?id=233145
Reviewed by Darin Adler.
Decoder::unwrapForTesting() is unnecessarily inefficient. It can take the whole
m_attachments data members from the decoder instead of calling removeAttachment()
repeatedly on the Decoder.
Also rename removeAttachment() to takeAttachment() since it returns the Attachment.
Update it to return a std::optional<Attachment> instead of using an out-parameter.
* Platform/IPC/Attachment.cpp:
(IPC::Attachment::decode):
* Platform/IPC/Attachment.h:
* Platform/IPC/Decoder.cpp:
(IPC::Decoder::unwrapForTesting):
(IPC::Decoder::takeAttachment):
(IPC::Decoder::removeAttachment): Deleted.
* Platform/IPC/Decoder.h:
* Platform/IPC/win/AttachmentWin.cpp:
(IPC::Attachment::decode):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (285865 => 285866)
--- trunk/Source/WebKit/ChangeLog 2021-11-16 16:51:30 UTC (rev 285865)
+++ trunk/Source/WebKit/ChangeLog 2021-11-16 16:57:55 UTC (rev 285866)
@@ -1,5 +1,30 @@
2021-11-16 Chris Dumez <[email protected]>
+ Decoder::unwrapForTesting() is unnecessarily inefficient
+ https://bugs.webkit.org/show_bug.cgi?id=233145
+
+ Reviewed by Darin Adler.
+
+ Decoder::unwrapForTesting() is unnecessarily inefficient. It can take the whole
+ m_attachments data members from the decoder instead of calling removeAttachment()
+ repeatedly on the Decoder.
+
+ Also rename removeAttachment() to takeAttachment() since it returns the Attachment.
+ Update it to return a std::optional<Attachment> instead of using an out-parameter.
+
+ * Platform/IPC/Attachment.cpp:
+ (IPC::Attachment::decode):
+ * Platform/IPC/Attachment.h:
+ * Platform/IPC/Decoder.cpp:
+ (IPC::Decoder::unwrapForTesting):
+ (IPC::Decoder::takeAttachment):
+ (IPC::Decoder::removeAttachment): Deleted.
+ * Platform/IPC/Decoder.h:
+ * Platform/IPC/win/AttachmentWin.cpp:
+ (IPC::Attachment::decode):
+
+2021-11-16 Chris Dumez <[email protected]>
+
Do some hardening in IPC::createMessageDecoder()
https://bugs.webkit.org/show_bug.cgi?id=233148
<rdar://75139294>
Modified: trunk/Source/WebKit/Platform/IPC/Attachment.cpp (285865 => 285866)
--- trunk/Source/WebKit/Platform/IPC/Attachment.cpp 2021-11-16 16:51:30 UTC (rev 285865)
+++ trunk/Source/WebKit/Platform/IPC/Attachment.cpp 2021-11-16 16:57:55 UTC (rev 285866)
@@ -56,11 +56,9 @@
encoder.addAttachment(WTFMove(*const_cast<Attachment*>(this)));
}
-bool Attachment::decode(Decoder& decoder, Attachment& attachment)
+std::optional<Attachment> Attachment::decode(Decoder& decoder)
{
- if (!decoder.removeAttachment(attachment))
- return false;
- return true;
+ return decoder.takeLastAttachment();
}
#endif
Modified: trunk/Source/WebKit/Platform/IPC/Attachment.h (285865 => 285866)
--- trunk/Source/WebKit/Platform/IPC/Attachment.h 2021-11-16 16:51:30 UTC (rev 285865)
+++ trunk/Source/WebKit/Platform/IPC/Attachment.h 2021-11-16 16:57:55 UTC (rev 285866)
@@ -26,6 +26,8 @@
#pragma once
+#include <optional>
+
#if OS(DARWIN) && !USE(UNIX_DOMAIN_SOCKETS)
#include <mach/mach_init.h>
#include <mach/mach_traps.h>
@@ -98,7 +100,7 @@
#endif
void encode(Encoder&) const;
- static WARN_UNUSED_RETURN bool decode(Decoder&, Attachment&);
+ static std::optional<Attachment> decode(Decoder&);
private:
Type m_type;
Modified: trunk/Source/WebKit/Platform/IPC/Decoder.cpp (285865 => 285866)
--- trunk/Source/WebKit/Platform/IPC/Decoder.cpp 2021-11-16 16:51:30 UTC (rev 285865)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.cpp 2021-11-16 16:57:55 UTC (rev 285866)
@@ -33,10 +33,6 @@
#include <stdio.h>
#include <wtf/StdLibExtras.h>
-#if PLATFORM(MAC)
-#include "ImportanceAssertion.h"
-#endif
-
namespace IPC {
static const uint8_t* copyBuffer(const uint8_t* buffer, size_t bufferSize)
@@ -147,11 +143,7 @@
{
ASSERT(decoder.isSyncMessage());
- Vector<Attachment> attachments;
- Attachment attachment;
- while (decoder.removeAttachment(attachment))
- attachments.append(WTFMove(attachment));
- attachments.reverse();
+ auto attachments = std::exchange(decoder.m_attachments, { });
DataReference wrappedMessage;
if (!decoder.decode(wrappedMessage))
@@ -218,13 +210,11 @@
return data;
}
-bool Decoder::removeAttachment(Attachment& attachment)
+std::optional<Attachment> Decoder::takeLastAttachment()
{
if (m_attachments.isEmpty())
- return false;
-
- attachment = m_attachments.takeLast();
- return true;
+ return std::nullopt;
+ return m_attachments.takeLast();
}
} // namespace IPC
Modified: trunk/Source/WebKit/Platform/IPC/Decoder.h (285865 => 285866)
--- trunk/Source/WebKit/Platform/IPC/Decoder.h 2021-11-16 16:51:30 UTC (rev 285865)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.h 2021-11-16 16:57:55 UTC (rev 285866)
@@ -27,8 +27,6 @@
#include "Attachment.h"
#include "MessageNames.h"
-#include "StringReference.h"
-#include <WebCore/SharedBuffer.h>
#include <wtf/OptionSet.h>
#include <wtf/Vector.h>
@@ -36,10 +34,6 @@
#include "ImportanceAssertion.h"
#endif
-#if HAVE(QOS_CLASSES)
-#include <pthread/qos.h>
-#endif
-
namespace IPC {
enum class MessageFlags : uint8_t;
@@ -140,7 +134,7 @@
return bufferIsLargeEnoughToContain(alignof(T), numElements * sizeof(T));
}
- bool removeAttachment(Attachment&);
+ std::optional<Attachment> takeLastAttachment();
static constexpr bool isIPCDecoder = true;
Modified: trunk/Source/WebKit/Platform/IPC/win/AttachmentWin.cpp (285865 => 285866)
--- trunk/Source/WebKit/Platform/IPC/win/AttachmentWin.cpp 2021-11-16 16:51:30 UTC (rev 285865)
+++ trunk/Source/WebKit/Platform/IPC/win/AttachmentWin.cpp 2021-11-16 16:57:55 UTC (rev 285866)
@@ -65,24 +65,21 @@
return success;
}
-bool Attachment::decode(Decoder& decoder, Attachment& attachment)
+std::optional<Attachment> Attachment::decode(Decoder& decoder)
{
- ASSERT_ARG(attachment, attachment.m_handle == INVALID_HANDLE_VALUE);
-
uint64_t sourceHandle;
if (!decoder.decode(sourceHandle))
- return false;
+ return std::nullopt;
uint32_t sourcePID;
if (!decoder.decode(sourcePID))
- return false;
+ return std::nullopt;
HANDLE duplicatedHandle;
if (!getDuplicatedHandle(reinterpret_cast<HANDLE>(sourceHandle), sourcePID, duplicatedHandle))
- return false;
+ return std::nullopt;
- attachment.m_handle = duplicatedHandle;
- return true;
+ return Attachment { duplicatedHandle };
}
} // namespace IPC
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes