Use pointer instead of std::optional<std::reference_wrapper<>>
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2018 00:50:19 +0000 (00:50 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2018 00:50:19 +0000 (00:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185186

Reviewed by Alex Christensen.

std::optional<T&> is not accepted in C++17 spec. So we replaced it
with std::optional<std::reference_wrapper<T>>.

In this patch, we replace it with T*, which is well-aligned to
WebKit's convention.

* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::iceServersFromConfiguration):
(WebCore::RTCPeerConnection::initializeConfiguration):
(WebCore::RTCPeerConnection::setConfiguration):
* css/parser/CSSParser.cpp:
(WebCore::CSSParser::parseSystemColor):
* css/parser/CSSParser.h:
* dom/DatasetDOMStringMap.cpp:
(WebCore::DatasetDOMStringMap::item const):
(WebCore::DatasetDOMStringMap::namedItem const):
* dom/DatasetDOMStringMap.h:
* dom/Element.cpp:
(WebCore::Element::insertAdjacentHTML):
* dom/Element.h:
* html/canvas/CanvasStyle.cpp:
(WebCore::parseColor):
* inspector/DOMEditor.cpp:
* platform/network/curl/CurlFormDataStream.cpp:
(WebCore::CurlFormDataStream::getPostData):
* platform/network/curl/CurlFormDataStream.h:
* platform/network/curl/CurlRequest.cpp:
(WebCore::CurlRequest::setupPOST):
* testing/MockCDMFactory.cpp:
(WebCore::MockCDMFactory::keysForSessionWithID const):
(WebCore::MockCDMInstance::updateLicense):
* testing/MockCDMFactory.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231288 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/css/parser/CSSParser.cpp
Source/WebCore/css/parser/CSSParser.h
Source/WebCore/dom/DatasetDOMStringMap.cpp
Source/WebCore/dom/DatasetDOMStringMap.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/html/canvas/CanvasStyle.cpp
Source/WebCore/inspector/DOMEditor.cpp
Source/WebCore/platform/network/curl/CurlFormDataStream.cpp
Source/WebCore/platform/network/curl/CurlFormDataStream.h
Source/WebCore/platform/network/curl/CurlRequest.cpp
Source/WebCore/testing/MockCDMFactory.cpp
Source/WebCore/testing/MockCDMFactory.h

index 1260753..b45afb3 100644 (file)
@@ -1,3 +1,43 @@
+2018-05-01  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Use pointer instead of std::optional<std::reference_wrapper<>>
+        https://bugs.webkit.org/show_bug.cgi?id=185186
+
+        Reviewed by Alex Christensen.
+
+        std::optional<T&> is not accepted in C++17 spec. So we replaced it
+        with std::optional<std::reference_wrapper<T>>.
+
+        In this patch, we replace it with T*, which is well-aligned to
+        WebKit's convention.
+
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::iceServersFromConfiguration):
+        (WebCore::RTCPeerConnection::initializeConfiguration):
+        (WebCore::RTCPeerConnection::setConfiguration):
+        * css/parser/CSSParser.cpp:
+        (WebCore::CSSParser::parseSystemColor):
+        * css/parser/CSSParser.h:
+        * dom/DatasetDOMStringMap.cpp:
+        (WebCore::DatasetDOMStringMap::item const):
+        (WebCore::DatasetDOMStringMap::namedItem const):
+        * dom/DatasetDOMStringMap.h:
+        * dom/Element.cpp:
+        (WebCore::Element::insertAdjacentHTML):
+        * dom/Element.h:
+        * html/canvas/CanvasStyle.cpp:
+        (WebCore::parseColor):
+        * inspector/DOMEditor.cpp:
+        * platform/network/curl/CurlFormDataStream.cpp:
+        (WebCore::CurlFormDataStream::getPostData):
+        * platform/network/curl/CurlFormDataStream.h:
+        * platform/network/curl/CurlRequest.cpp:
+        (WebCore::CurlRequest::setupPOST):
+        * testing/MockCDMFactory.cpp:
+        (WebCore::MockCDMFactory::keysForSessionWithID const):
+        (WebCore::MockCDMInstance::updateLicense):
+        * testing/MockCDMFactory.h:
+
 2018-05-02  Keith Rollin  <krollin@apple.com>
 
         Add facility for tracking times and results of page and resource loading
index 536c552..0e3c4f6 100644 (file)
@@ -301,12 +301,12 @@ void RTCPeerConnection::queuedAddIceCandidate(RTCIceCandidate* rtcCandidate, DOM
 }
 
 // Implementation of https://w3c.github.io/webrtc-pc/#set-pc-configuration
-static inline ExceptionOr<Vector<MediaEndpointConfiguration::IceServerInfo>> iceServersFromConfiguration(RTCConfiguration& newConfiguration, std::optional<std::reference_wrapper<const RTCConfiguration>> existingConfiguration, bool isLocalDescriptionSet)
+static inline ExceptionOr<Vector<MediaEndpointConfiguration::IceServerInfo>> iceServersFromConfiguration(RTCConfiguration& newConfiguration, const RTCConfiguration* existingConfiguration, bool isLocalDescriptionSet)
 {
-    if (existingConfiguration && newConfiguration.bundlePolicy != existingConfiguration->get().bundlePolicy)
+    if (existingConfiguration && newConfiguration.bundlePolicy != existingConfiguration->bundlePolicy)
         return Exception { InvalidModificationError, "IceTransportPolicy does not match existing policy" };
 
-    if (existingConfiguration && newConfiguration.iceCandidatePoolSize != existingConfiguration->get().iceCandidatePoolSize && isLocalDescriptionSet)
+    if (existingConfiguration && newConfiguration.iceCandidatePoolSize != existingConfiguration->iceCandidatePoolSize && isLocalDescriptionSet)
         return Exception { InvalidModificationError, "IceTransportPolicy pool size does not match existing pool size" };
 
     Vector<MediaEndpointConfiguration::IceServerInfo> servers;
@@ -342,7 +342,7 @@ ExceptionOr<void> RTCPeerConnection::initializeConfiguration(RTCConfiguration&&
 {
     INFO_LOG(LOGIDENTIFIER);
 
-    auto servers = iceServersFromConfiguration(configuration, std::nullopt, false);
+    auto servers = iceServersFromConfiguration(configuration, nullptr, false);
     if (servers.hasException())
         return servers.releaseException();
 
@@ -360,7 +360,7 @@ ExceptionOr<void> RTCPeerConnection::setConfiguration(RTCConfiguration&& configu
 
     INFO_LOG(LOGIDENTIFIER);
 
-    auto servers = iceServersFromConfiguration(configuration, std::cref(m_configuration), m_backend->isLocalDescriptionSet());
+    auto servers = iceServersFromConfiguration(configuration, &m_configuration, m_backend->isLocalDescriptionSet());
     if (servers.hasException())
         return servers.releaseException();
 
index 33f52e1..8413801 100644 (file)
@@ -178,14 +178,14 @@ Color CSSParser::parseColor(const String& string, bool strict)
     return primitiveValue.color();
 }
 
-Color CSSParser::parseSystemColor(const String& string, std::optional<std::reference_wrapper<const CSSParserContext>> context)
+Color CSSParser::parseSystemColor(const String& string, const CSSParserContext* context)
 {
     CSSValueID id = cssValueKeywordID(string);
     if (!StyleColor::isSystemColor(id))
         return Color();
 
     OptionSet<StyleColor::Options> options;
-    if (context && context->get().useSystemAppearance)
+    if (context && context->useSystemAppearance)
         options |= StyleColor::Options::UseSystemAppearance;
     return RenderTheme::singleton().systemColor(id, options);
 }
index aee78e5..2930d45 100644 (file)
@@ -78,7 +78,7 @@ public:
     RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, const CustomPropertyValueMap& customProperties, TextDirection, WritingMode);
 
     static Color parseColor(const String&, bool strict = false);
-    static Color parseSystemColor(const String&, std::optional<std::reference_wrapper<const CSSParserContext>>);
+    static Color parseSystemColor(const String&, const CSSParserContext*);
 
 private:
     ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important);
index 8e86aee..ec6315c 100644 (file)
@@ -188,7 +188,7 @@ Vector<String> DatasetDOMStringMap::supportedPropertyNames() const
     return names;
 }
 
-std::optional<std::reference_wrapper<const AtomicString>> DatasetDOMStringMap::item(const String& propertyName) const
+const AtomicString* DatasetDOMStringMap::item(const String& propertyName) const
 {
     if (m_element.hasAttributes()) {
         AttributeIteratorAccessor attributeIteratorAccessor = m_element.attributesIterator();
@@ -198,23 +198,23 @@ std::optional<std::reference_wrapper<const AtomicString>> DatasetDOMStringMap::i
             // Building a new AtomicString in that case is overkill so we do a direct character comparison.
             const Attribute& attribute = *attributeIteratorAccessor.begin();
             if (propertyNameMatchesAttributeName(propertyName, attribute.localName()))
-                return std::cref(attribute.value());
+                return &attribute.value();
         } else {
             AtomicString attributeName = convertPropertyNameToAttributeName(propertyName);
             for (const Attribute& attribute : attributeIteratorAccessor) {
                 if (attribute.localName() == attributeName)
-                    return std::cref(attribute.value());
+                    return &attribute.value();
             }
         }
     }
 
-    return std::nullopt;
+    return nullptr;
 }
 
 String DatasetDOMStringMap::namedItem(const AtomicString& name) const
 {
-    if (auto value = item(name))
-        return value->get();
+    if (const auto* value = item(name))
+        return *value;
     return String { };
 }
 
index d6d10d1..9100db8 100644 (file)
@@ -53,7 +53,7 @@ public:
     Element& element() { return m_element; }
 
 private:
-    std::optional<std::reference_wrapper<const AtomicString>> item(const String& name) const;
+    const AtomicString* item(const String& name) const;
 
     Element& m_element;
 };
index 273d8ca..24faa3f 100644 (file)
@@ -3733,7 +3733,7 @@ static ExceptionOr<Ref<Element>> contextElementForInsertion(const String& where,
 }
 
 // https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml
-ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String& markup, std::optional<std::reference_wrapper<NodeVector>> addedNodes)
+ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String& markup, NodeVector* addedNodes)
 {
     // Steps 1 and 2.
     auto contextElement = contextElementForInsertion(where, *this);
@@ -3747,7 +3747,7 @@ ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String&
     if (UNLIKELY(addedNodes)) {
         // Must be called before insertAdjacent, as otherwise the children of fragment will be moved
         // to their new parent and will be harder to keep track of.
-        addedNodes->get() = collectChildNodes(fragment.returnValue());
+        *addedNodes = collectChildNodes(fragment.returnValue());
     }
 
     // Step 4.
@@ -3759,7 +3759,7 @@ ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String&
 
 ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String& markup)
 {
-    return insertAdjacentHTML(where, markup, std::nullopt);
+    return insertAdjacentHTML(where, markup, nullptr);
 }
 
 ExceptionOr<void> Element::insertAdjacentText(const String& where, const String& text)
index 9af4113..1c4db86 100644 (file)
@@ -314,7 +314,7 @@ public:
     WEBCORE_EXPORT void setTabIndex(int);
     virtual RefPtr<Element> focusDelegate();
 
-    ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html, std::optional<std::reference_wrapper<NodeVector>> addedNodes);
+    ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html, NodeVector* addedNodes);
 
     WEBCORE_EXPORT ExceptionOr<Element*> insertAdjacentElement(const String& where, Element& newChild);
     WEBCORE_EXPORT ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html);
index ff49ad1..aca8a60 100644 (file)
@@ -53,7 +53,7 @@ static Color parseColor(const String& colorString)
     Color color = CSSParser::parseColor(colorString);
     if (color.isValid())
         return color;
-    return CSSParser::parseSystemColor(colorString, std::nullopt);
+    return CSSParser::parseSystemColor(colorString, nullptr);
 }
 
 Color currentColor(HTMLCanvasElement* canvas)
index 59eccd4..e0af0fd 100644 (file)
@@ -266,7 +266,7 @@ private:
 
     ExceptionOr<void> redo() final
     {
-        auto result = m_element->insertAdjacentHTML(m_position, m_html, std::ref(m_addedNodes));
+        auto result = m_element->insertAdjacentHTML(m_position, m_html, &m_addedNodes);
         if (result.hasException())
             return result.releaseException();
         return { };
index 2ad6a18..889892d 100644 (file)
@@ -69,15 +69,15 @@ void CurlFormDataStream::clean()
     }
 }
 
-std::optional<std::reference_wrapper<const Vector<char>>> CurlFormDataStream::getPostData()
+const Vector<char>* CurlFormDataStream::getPostData()
 {
     if (!m_formData)
-        return std::nullopt;
+        return nullptr;
 
     if (!m_postData)
         m_postData = std::make_unique<Vector<char>>(m_formData->flatten());
 
-    return std::cref(*m_postData);
+    return m_postData.get();
 }
 
 bool CurlFormDataStream::shouldUseChunkTransfer()
index d33df78..4f1b308 100644 (file)
@@ -41,7 +41,7 @@ public:
 
     size_t elementSize() { return m_formData ? m_formData->elements().size() : 0; }
 
-    std::optional<std::reference_wrapper<const Vector<char>>> getPostData();
+    const Vector<char>* getPostData();
     bool shouldUseChunkTransfer();
     unsigned long long totalSize();
 
index 00799a3..f2d0c9b 100644 (file)
@@ -489,9 +489,9 @@ void CurlRequest::setupPOST(ResourceRequest& request)
 
     // Do not stream for simple POST data
     if (elementSize == 1) {
-        auto postData = m_formDataStream.getPostData();
-        if (postData && postData->get().size())
-            m_curlHandle->setPostFields(postData->get().data(), postData->get().size());
+        const auto* postData = m_formDataStream.getPostData();
+        if (postData && postData->size())
+            m_curlHandle->setPostFields(postData->data(), postData->size());
     } else
         setupSendData(false);
 }
index 445ea9b..e2fdfbc 100644 (file)
@@ -81,12 +81,12 @@ Vector<Ref<SharedBuffer>> MockCDMFactory::removeKeysFromSessionWithID(const Stri
     return WTFMove(it->value);
 }
 
-std::optional<std::reference_wrapper<const Vector<Ref<SharedBuffer>>>> MockCDMFactory::keysForSessionWithID(const String& id) const
+const Vector<Ref<SharedBuffer>>* MockCDMFactory::keysForSessionWithID(const String& id) const
 {
     auto it = m_sessions.find(id);
     if (it == m_sessions.end())
-        return std::nullopt;
-    return std::cref(it->value);
+        return nullptr;
+    return &it->value;
 }
 
 void MockCDMFactory::setSupportedDataTypes(Vector<String>&& types)
@@ -314,11 +314,11 @@ void MockCDMInstance::updateLicense(const String& sessionID, LicenseType, const
 
     std::optional<KeyStatusVector> changedKeys;
     if (responseVector.contains(String(ASCIILiteral("keys-changed")))) {
-        std::optional<std::reference_wrapper<const Vector<Ref<SharedBuffer>>>> keys = factory->keysForSessionWithID(sessionID);
+        const auto* keys = factory->keysForSessionWithID(sessionID);
         if (keys) {
             KeyStatusVector keyStatusVector;
-            keyStatusVector.reserveInitialCapacity(keys->get().size());
-            for (auto& key : (*keys).get())
+            keyStatusVector.reserveInitialCapacity(keys->size());
+            for (auto& key : *keys)
                 keyStatusVector.uncheckedAppend({ key.copyRef(), KeyStatus::Usable });
 
             changedKeys = WTFMove(keyStatusVector);
index 3e6db21..418d390 100644 (file)
@@ -73,7 +73,7 @@ public:
     bool hasSessionWithID(const String& id) { return m_sessions.contains(id); }
     void removeSessionWithID(const String& id) { m_sessions.remove(id); }
     void addKeysToSessionWithID(const String& id, Vector<Ref<SharedBuffer>>&&);
-    std::optional<std::reference_wrapper<const Vector<Ref<SharedBuffer>>>> keysForSessionWithID(const String& id) const;
+    const Vector<Ref<SharedBuffer>>* keysForSessionWithID(const String& id) const;
     Vector<Ref<SharedBuffer>> removeKeysFromSessionWithID(const String& id);
 
 private: