⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 285866 in webkit


Ignore:
Timestamp:
Nov 16, 2021, 8:57:55 AM (5 years ago)
Author:
Chris Dumez
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):

Location:
trunk/Source/WebKit
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r285865 r285866  
     12021-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
    1262021-11-16  Chris Dumez  <cdumez@apple.com>
    227
  • trunk/Source/WebKit/Platform/IPC/Attachment.cpp

    r224351 r285866  
    5757}
    5858
    59 bool Attachment::decode(Decoder& decoder, Attachment& attachment)
     59std::optional<Attachment> Attachment::decode(Decoder& decoder)
    6060{
    61     if (!decoder.removeAttachment(attachment))
    62         return false;
    63     return true;
     61    return decoder.takeLastAttachment();
    6462}
    6563#endif
  • trunk/Source/WebKit/Platform/IPC/Attachment.h

    r284213 r285866  
    2626
    2727#pragma once
     28
     29#include <optional>
    2830
    2931#if OS(DARWIN) && !USE(UNIX_DOMAIN_SOCKETS)
     
    99101
    100102    void encode(Encoder&) const;
    101     static WARN_UNUSED_RETURN bool decode(Decoder&, Attachment&);
     103    static std::optional<Attachment> decode(Decoder&);
    102104   
    103105private:
  • trunk/Source/WebKit/Platform/IPC/Decoder.cpp

    r285818 r285866  
    3434#include <wtf/StdLibExtras.h>
    3535
    36 #if PLATFORM(MAC)
    37 #include "ImportanceAssertion.h"
    38 #endif
    39 
    4036namespace IPC {
    4137
     
    148144    ASSERT(decoder.isSyncMessage());
    149145
    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, { });
    155147
    156148    DataReference wrappedMessage;
     
    219211}
    220212
    221 bool Decoder::removeAttachment(Attachment& attachment)
     213std::optional<Attachment> Decoder::takeLastAttachment()
    222214{
    223215    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();
    228218}
    229219
  • trunk/Source/WebKit/Platform/IPC/Decoder.h

    r285818 r285866  
    2828#include "Attachment.h"
    2929#include "MessageNames.h"
    30 #include "StringReference.h"
    31 #include <WebCore/SharedBuffer.h>
    3230#include <wtf/OptionSet.h>
    3331#include <wtf/Vector.h>
     
    3533#if PLATFORM(MAC)
    3634#include "ImportanceAssertion.h"
    37 #endif
    38 
    39 #if HAVE(QOS_CLASSES)
    40 #include <pthread/qos.h>
    4135#endif
    4236
     
    141135    }
    142136
    143     bool removeAttachment(Attachment&);
     137    std::optional<Attachment> takeLastAttachment();
    144138
    145139    static constexpr bool isIPCDecoder = true;
  • trunk/Source/WebKit/Platform/IPC/win/AttachmentWin.cpp

    r272058 r285866  
    6666}
    6767
    68 bool Attachment::decode(Decoder& decoder, Attachment& attachment)
     68std::optional<Attachment> Attachment::decode(Decoder& decoder)
    6969{
    70     ASSERT_ARG(attachment, attachment.m_handle == INVALID_HANDLE_VALUE);
    71 
    7270    uint64_t sourceHandle;
    7371    if (!decoder.decode(sourceHandle))
    74         return false;
     72        return std::nullopt;
    7573
    7674    uint32_t sourcePID;
    7775    if (!decoder.decode(sourcePID))
    78         return false;
     76        return std::nullopt;
    7977
    8078    HANDLE duplicatedHandle;
    8179    if (!getDuplicatedHandle(reinterpret_cast<HANDLE>(sourceHandle), sourcePID, duplicatedHandle))
    82         return false;
     80        return std::nullopt;
    8381
    84     attachment.m_handle = duplicatedHandle;
    85     return true;
     82    return Attachment { duplicatedHandle };
    8683}
    8784
Note: See TracChangeset for help on using the changeset viewer.