Changeset 207627 in webkit
- Timestamp:
- Oct 20, 2016 11:27:28 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r207585 r207627 1 2016-10-19 Sam Weinig <sam@webkit.org> 2 3 Add convenience function that combines WTF::visit(...) with WTF::makeVisitor(...) 4 https://bugs.webkit.org/show_bug.cgi?id=163713 5 6 Reviewed by Dan Bernstein. 7 8 - Add WTF::switchOn which merges WTF::visit with WTF::makeVisitor in the following 9 way: 10 WTF::visit(WTF::makeVisitor(...), variant) 11 12 * wtf/Variant.h: 13 (WTF::switchOn): 14 1 15 2016-10-19 Alex Christensen <achristensen@webkit.org> 2 16 -
trunk/Source/WTF/wtf/Variant.h
r207517 r207627 49 49 #include <utility> 50 50 #include <wtf/Compiler.h> 51 #include <wtf/StdLibExtras.h> 51 52 52 53 #if COMPILER(MSVC) … … 2041 2042 }; 2042 2043 2044 // -- WebKit Additions -- 2045 2046 template<class V, class... F> 2047 auto switchOn(V&& v, F&&... f) -> decltype(visit(makeVisitor(std::forward<F>(f)...), std::forward<V>(v))) 2048 { 2049 return visit(makeVisitor(std::forward<F>(f)...), std::forward<V>(v)); 2050 } 2051 2043 2052 } // namespace WTF 2044 2053 -
trunk/Source/WebCore/ChangeLog
r207622 r207627 1 2016-10-20 Sam Weinig <sam@webkit.org> 2 3 Add convenience function that combines WTF::visit(...) with WTF::makeVisitor(...) 4 https://bugs.webkit.org/show_bug.cgi?id=163713 5 6 Reviewed by Dan Bernstein. 7 8 Switch uses of WTF::visit to use WTF::switchOn. 9 10 * dom/MessageEvent.cpp: 11 (WebCore::MessageEvent::source): 12 * dom/Node.cpp: 13 (WebCore::nodeSetPreTransformedFromNodeOrStringVector): 14 (WebCore::Node::convertNodesOrStringsIntoNode): 15 * html/HTMLSelectElement.cpp: 16 (WebCore::HTMLSelectElement::add): 17 * html/track/TrackEvent.cpp: 18 (WebCore::TrackEvent::TrackEvent): 19 * testing/TypeConversions.h: 20 (WebCore::TypeConversions::typeConversionsDictionaryUnionType): 21 1 22 2016-10-20 Dave Hyatt <hyatt@apple.com> 2 23 -
trunk/Source/WebCore/dom/MessageEvent.cpp
r207517 r207627 173 173 return nullptr; 174 174 175 auto visitor = WTF::makeVisitor(175 return WTF::switchOn(m_source.value(), 176 176 [](const RefPtr<DOMWindow>& window) -> EventTarget* { return const_cast<EventTarget*>(static_cast<const EventTarget*>(window.get())); }, 177 177 [](const RefPtr<MessagePort>& messagePort) -> EventTarget* { return const_cast<EventTarget*>(static_cast<const EventTarget*>(messagePort.get())); } 178 178 ); 179 180 return WTF::visit(visitor, m_source.value());181 179 } 182 180 -
trunk/Source/WebCore/dom/Node.cpp
r207517 r207627 439 439 { 440 440 HashSet<RefPtr<Node>> nodeSet; 441 442 auto visitor = WTF::makeVisitor( 443 [&](const RefPtr<Node>& node) { nodeSet.add(const_cast<Node*>(node.get())); }, 444 [](const String&) { } 445 ); 446 447 for (const auto& variant : vector) 448 WTF::visit(visitor, variant); 441 for (const auto& variant : vector) { 442 WTF::switchOn(variant, 443 [&](const RefPtr<Node>& node) { nodeSet.add(const_cast<Node*>(node.get())); }, 444 [](const String&) { } 445 ); 446 } 449 447 450 448 return nodeSet; … … 476 474 Vector<Ref<Node>> nodes; 477 475 nodes.reserveInitialCapacity(nodeOrStringVector.size()); 478 479 auto visitor = WTF::makeVisitor( 480 [&](RefPtr<Node>& node) { nodes.uncheckedAppend(*node.get()); }, 481 [&](String& string) { nodes.uncheckedAppend(Text::create(document(), string)); } 482 ); 483 484 for (auto& variant : nodeOrStringVector) 485 WTF::visit(visitor, variant); 476 for (auto& variant : nodeOrStringVector) { 477 WTF::switchOn(variant, 478 [&](RefPtr<Node>& node) { nodes.uncheckedAppend(*node.get()); }, 479 [&](String& string) { nodes.uncheckedAppend(Text::create(document(), string)); } 480 ); 481 } 486 482 487 483 if (nodes.size() == 1) -
trunk/Source/WebCore/html/HTMLSelectElement.cpp
r207517 r207627 226 226 HTMLElement* beforeElement = nullptr; 227 227 if (before) { 228 auto visitor = WTF::makeVisitor(228 beforeElement = WTF::switchOn(before.value(), 229 229 [](const RefPtr<HTMLElement>& element) -> HTMLElement* { return element.get(); }, 230 230 [this](int index) -> HTMLElement* { return item(index); } 231 231 ); 232 233 beforeElement = WTF::visit(visitor, before.value()); 234 } 235 HTMLElement& toInsert = WTF::visit([](const auto& htmlElement) -> HTMLElement& { 236 return *htmlElement; 237 }, element); 232 } 233 HTMLElement& toInsert = WTF::switchOn(element, 234 [](const auto& htmlElement) -> HTMLElement& { return *htmlElement; } 235 ); 238 236 239 237 -
trunk/Source/WebCore/html/track/TrackEvent.cpp
r207517 r207627 44 44 { 45 45 if (initializer.track) { 46 m_track = WTF:: visit([](const auto& trackbase) -> TrackBase* {47 return trackbase.get();48 }, *initializer.track);46 m_track = WTF::switchOn(*initializer.track, 47 [](const auto& trackbase) -> TrackBase* { return trackbase.get(); } 48 ); 49 49 } 50 50 } -
trunk/Source/WebCore/testing/TypeConversions.h
r207575 r207627 112 112 UnionType typeConversionsDictionaryUnionType() 113 113 { 114 return WTF:: visit(WTF::makeVisitor(114 return WTF::switchOn(m_typeConversionsDictionaryUnionValue, 115 115 [](const RefPtr<Node>&) -> UnionType { return UnionType::Node; }, 116 116 [](const Vector<String>&) -> UnionType { return UnionType::Sequence; }, 117 117 [](const OtherDictionary&) -> UnionType { return UnionType::Dictionary; } 118 ) , m_typeConversionsDictionaryUnionValue);118 ); 119 119 } 120 120 -
trunk/Tools/ChangeLog
r207617 r207627 1 2016-10-20 Sam Weinig <sam@webkit.org> 2 3 Add convenience function that combines WTF::visit(...) with WTF::makeVisitor(...) 4 https://bugs.webkit.org/show_bug.cgi?id=163713 5 6 Reviewed by Dan Bernstein. 7 8 * TestWebKitAPI/Tests/WTF/Variant.cpp: 9 Add test for WTF::switchOn() 10 1 11 2016-10-20 Fujii Hironori <Hironori.Fujii@sony.com> 2 12 -
trunk/Tools/TestWebKitAPI/Tests/WTF/Variant.cpp
r207517 r207627 142 142 } 143 143 144 TEST(WTF_Variant, VisitorUsingSwitchOn) 145 { 146 enum class Type { 147 None, 148 Int, 149 Float, 150 String, 151 }; 152 153 Type type = Type::None; 154 155 Variant<int, float, String> variant = 8; 156 type = WTF::switchOn(variant, 157 [](int) { return Type::Int; }, 158 [](float) { return Type::Float; }, 159 [](String) { return Type::String; } 160 ); 161 EXPECT_TRUE(Type::Int == type); 162 163 164 variant = 1.0f; 165 type = WTF::switchOn(variant, 166 [](int) { return Type::Int; }, 167 [](float) { return Type::Float; }, 168 [](String) { return Type::String; } 169 ); 170 EXPECT_TRUE(Type::Float == type); 171 172 173 variant = "hello"; 174 type = WTF::switchOn(variant, 175 [](int) { return Type::Int; }, 176 [](float) { return Type::Float; }, 177 [](String) { return Type::String; } 178 ); 179 EXPECT_TRUE(Type::String == type); 180 } 181 144 182 TEST(WTF_Variant, ConstructorDestructor) 145 183 {
Note: See TracChangeset
for help on using the changeset viewer.