Changeset 285866 in webkit
- Timestamp:
- Nov 16, 2021, 8:57:55 AM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 6 edited
-
ChangeLog (modified) (1 diff)
-
Platform/IPC/Attachment.cpp (modified) (1 diff)
-
Platform/IPC/Attachment.h (modified) (2 diffs)
-
Platform/IPC/Decoder.cpp (modified) (3 diffs)
-
Platform/IPC/Decoder.h (modified) (3 diffs)
-
Platform/IPC/win/AttachmentWin.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r285865 r285866 1 2021-11-16 Chris Dumez <cdumez@apple.com> 2 3 Decoder::unwrapForTesting() is unnecessarily inefficient 4 https://bugs.webkit.org/show_bug.cgi?id=233145 5 6 Reviewed by Darin Adler. 7 8 Decoder::unwrapForTesting() is unnecessarily inefficient. It can take the whole 9 m_attachments data members from the decoder instead of calling removeAttachment() 10 repeatedly on the Decoder. 11 12 Also rename removeAttachment() to takeAttachment() since it returns the Attachment. 13 Update it to return a std::optional<Attachment> instead of using an out-parameter. 14 15 * Platform/IPC/Attachment.cpp: 16 (IPC::Attachment::decode): 17 * Platform/IPC/Attachment.h: 18 * Platform/IPC/Decoder.cpp: 19 (IPC::Decoder::unwrapForTesting): 20 (IPC::Decoder::takeAttachment): 21 (IPC::Decoder::removeAttachment): Deleted. 22 * Platform/IPC/Decoder.h: 23 * Platform/IPC/win/AttachmentWin.cpp: 24 (IPC::Attachment::decode): 25 1 26 2021-11-16 Chris Dumez <cdumez@apple.com> 2 27 -
trunk/Source/WebKit/Platform/IPC/Attachment.cpp
r224351 r285866 57 57 } 58 58 59 bool Attachment::decode(Decoder& decoder, Attachment& attachment)59 std::optional<Attachment> Attachment::decode(Decoder& decoder) 60 60 { 61 if (!decoder.removeAttachment(attachment)) 62 return false; 63 return true; 61 return decoder.takeLastAttachment(); 64 62 } 65 63 #endif -
trunk/Source/WebKit/Platform/IPC/Attachment.h
r284213 r285866 26 26 27 27 #pragma once 28 29 #include <optional> 28 30 29 31 #if OS(DARWIN) && !USE(UNIX_DOMAIN_SOCKETS) … … 99 101 100 102 void encode(Encoder&) const; 101 static WARN_UNUSED_RETURN bool decode(Decoder&, Attachment&);103 static std::optional<Attachment> decode(Decoder&); 102 104 103 105 private: -
trunk/Source/WebKit/Platform/IPC/Decoder.cpp
r285818 r285866 34 34 #include <wtf/StdLibExtras.h> 35 35 36 #if PLATFORM(MAC)37 #include "ImportanceAssertion.h"38 #endif39 40 36 namespace IPC { 41 37 … … 148 144 ASSERT(decoder.isSyncMessage()); 149 145 150 Vector<Attachment> attachments; 151 Attachment attachment; 152 while (decoder.removeAttachment(attachment)) 153 attachments.append(WTFMove(attachment)); 154 attachments.reverse(); 146 auto attachments = std::exchange(decoder.m_attachments, { }); 155 147 156 148 DataReference wrappedMessage; … … 219 211 } 220 212 221 bool Decoder::removeAttachment(Attachment& attachment)213 std::optional<Attachment> Decoder::takeLastAttachment() 222 214 { 223 215 if (m_attachments.isEmpty()) 224 return false; 225 226 attachment = m_attachments.takeLast(); 227 return true; 216 return std::nullopt; 217 return m_attachments.takeLast(); 228 218 } 229 219 -
trunk/Source/WebKit/Platform/IPC/Decoder.h
r285818 r285866 28 28 #include "Attachment.h" 29 29 #include "MessageNames.h" 30 #include "StringReference.h"31 #include <WebCore/SharedBuffer.h>32 30 #include <wtf/OptionSet.h> 33 31 #include <wtf/Vector.h> … … 35 33 #if PLATFORM(MAC) 36 34 #include "ImportanceAssertion.h" 37 #endif38 39 #if HAVE(QOS_CLASSES)40 #include <pthread/qos.h>41 35 #endif 42 36 … … 141 135 } 142 136 143 bool removeAttachment(Attachment&);137 std::optional<Attachment> takeLastAttachment(); 144 138 145 139 static constexpr bool isIPCDecoder = true; -
trunk/Source/WebKit/Platform/IPC/win/AttachmentWin.cpp
r272058 r285866 66 66 } 67 67 68 bool Attachment::decode(Decoder& decoder, Attachment& attachment)68 std::optional<Attachment> Attachment::decode(Decoder& decoder) 69 69 { 70 ASSERT_ARG(attachment, attachment.m_handle == INVALID_HANDLE_VALUE);71 72 70 uint64_t sourceHandle; 73 71 if (!decoder.decode(sourceHandle)) 74 return false;72 return std::nullopt; 75 73 76 74 uint32_t sourcePID; 77 75 if (!decoder.decode(sourcePID)) 78 return false;76 return std::nullopt; 79 77 80 78 HANDLE duplicatedHandle; 81 79 if (!getDuplicatedHandle(reinterpret_cast<HANDLE>(sourceHandle), sourcePID, duplicatedHandle)) 82 return false;80 return std::nullopt; 83 81 84 attachment.m_handle = duplicatedHandle; 85 return true; 82 return Attachment { duplicatedHandle }; 86 83 } 87 84
Note:
See TracChangeset
for help on using the changeset viewer.