Using StringView.split() instead of String.split() in some places
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 May 2017 22:51:40 +0000 (22:51 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 May 2017 22:51:40 +0000 (22:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170925

Reviewed by Darin Adler.

Source/WebCore:

Replace some uses of String.split() with StringView.split() (added in r211087) as the latter
avoids the need to allocate an intermediary Vector of substrings. Instead StringView.split()
returns an iterator for traversing the substrings.

No functionality changed. So, no new tests.

* accessibility/AccessibilityObject.cpp: Convert some typedefs to modern C++ using declarations.
(WebCore::ASCIICaseInsensitiveStringViewHashTranslator::hash): Added.
(WebCore::ASCIICaseInsensitiveStringViewHashTranslator::equal): Added.
(WebCore::AccessibilityObject::ariaRoleToWebCoreRole): Modified code to use StringView.split().
(WebCore::AccessibilityObject::elementsFromAttribute): Ditto.
* dom/TreeScope.cpp:
(WebCore::TreeScope::getElementById): Added.
* dom/TreeScope.h:
* html/LinkRelAttribute.cpp:
(WebCore::LinkRelAttribute::LinkRelAttribute): Modified code to use StringView.split().
* html/parser/XSSAuditor.cpp:
(WebCore::semicolonSeparatedValueContainsJavaScriptURL): Ditto.
* platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm:
(WebCore::CDMPrivateMediaSourceAVFObjC::createSession): Ditto.
* platform/network/CacheValidation.cpp:
(WebCore::collectVaryingRequestHeaders): Simplify code by using the String.split(UChar, Vector<String>&) overload.
* svg/SVGAnimationElement.cpp:
(WebCore::parseKeyTimes): Modified code to use StringView.split().
* svg/SVGToOTFFontConversion.cpp:
(WebCore::SVGToOTFFontConverter::SVGToOTFFontConverter): Ditto.
* testing/Internals.cpp:
(WebCore::Internals::setMediaSessionRestrictions): Ditto.
(WebCore::Internals::setMediaElementRestrictions): Ditto.
(WebCore::Internals::setAudioContextRestrictions): Ditto.
(WebCore::Internals::setPageMuted): Ditto.
* testing/Internals.h:

Source/WTF:

Add HashMap::get() overload that takes a HashTranslator.

* wtf/HashMap.h:

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

15 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/HashMap.h
Source/WTF/wtf/text/StringHash.h
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/dom/TreeScope.cpp
Source/WebCore/dom/TreeScope.h
Source/WebCore/html/LinkRelAttribute.cpp
Source/WebCore/html/parser/XSSAuditor.cpp
Source/WebCore/platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm
Source/WebCore/platform/network/CacheValidation.cpp
Source/WebCore/svg/SVGAnimationElement.cpp
Source/WebCore/svg/SVGToOTFFontConversion.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h

index ab61e9b..0281d62 100644 (file)
@@ -1,3 +1,14 @@
+2017-05-02  Daniel Bates  <dabates@apple.com>
+
+        Using StringView.split() instead of String.split() in some places
+        https://bugs.webkit.org/show_bug.cgi?id=170925
+
+        Reviewed by Darin Adler.
+
+        Add HashMap::get() overload that takes a HashTranslator.
+
+        * wtf/HashMap.h:
+
 2017-05-01  Dan Bernstein  <mitz@apple.com>
 
         [Xcode] It’s easy to accidentally install a WTF header outside /usr/local/include/wtf
index 49ef29f..bd8bd70 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2008, 2011, 2013, 2017 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -65,6 +65,8 @@ private:
     class HashMapKeysProxy;
     class HashMapValuesProxy;
 
+    using IdentityTranslatorType = typename HashTableType::IdentityTranslatorType;
+
 public:
     typedef HashTableIteratorAdapter<HashTableType, KeyValuePairType> iterator;
     typedef HashTableConstIteratorAdapter<HashTableType, KeyValuePairType> const_iterator;
@@ -142,6 +144,7 @@ public:
     template<typename HashTranslator, typename T> iterator find(const T&);
     template<typename HashTranslator, typename T> const_iterator find(const T&) const;
     template<typename HashTranslator, typename T> bool contains(const T&) const;
+    template<typename HashTranslator, typename T> MappedPeekType get(const T&) const;
 
     // An alternate version of add() that finds the object by hashing and comparing
     // with some other type, to avoid the cost of type conversion if the object is already
@@ -294,6 +297,16 @@ HashMap<T, U, V, W, X>::find(const TYPE& value) const
 
 template<typename T, typename U, typename V, typename W, typename X>
 template<typename HashTranslator, typename TYPE>
+auto HashMap<T, U, V, W, X>::get(const TYPE& value) const -> MappedPeekType
+{
+    auto* entry = const_cast<HashTableType&>(m_impl).template lookup<HashMapTranslatorAdapter<KeyValuePairTraits, HashTranslator>>(value);
+    if (!entry)
+        return MappedTraits::peek(MappedTraits::emptyValue());
+    return MappedTraits::peek(entry->value);
+}
+
+template<typename T, typename U, typename V, typename W, typename X>
+template<typename HashTranslator, typename TYPE>
 inline bool HashMap<T, U, V, W, X>::contains(const TYPE& value) const
 {
     return m_impl.template contains<HashMapTranslatorAdapter<KeyValuePairTraits, HashTranslator>>(value);
@@ -389,18 +402,15 @@ auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::ensure(
 }
     
 template<typename T, typename U, typename V, typename W, typename MappedTraits>
-auto HashMap<T, U, V, W, MappedTraits>::get(const KeyType& key) const -> MappedPeekType
+inline auto HashMap<T, U, V, W, MappedTraits>::get(const KeyType& key) const -> MappedPeekType
 {
-    KeyValuePairType* entry = const_cast<HashTableType&>(m_impl).lookup(key);
-    if (!entry)
-        return MappedTraits::peek(MappedTraits::emptyValue());
-    return MappedTraits::peek(entry->value);
+    return get<IdentityTranslatorType>(key);
 }
 
 template<typename T, typename U, typename V, typename W, typename MappedTraits>
 ALWAYS_INLINE auto HashMap<T, U, V, W, MappedTraits>::fastGet(const KeyType& key) const -> MappedPeekType
 {
-    KeyValuePairType* entry = const_cast<HashTableType&>(m_impl).template inlineLookup<typename HashTableType::IdentityTranslatorType>(key);
+    KeyValuePairType* entry = const_cast<HashTableType&>(m_impl).template inlineLookup<IdentityTranslatorType>(key);
     if (!entry)
         return MappedTraits::peek(MappedTraits::emptyValue());
     return MappedTraits::peek(entry->value);
index a944a07..c1fa7e2 100644 (file)
@@ -175,6 +175,22 @@ namespace WTF {
         }
     };
 
+    // FIXME: Find a way to incorporate this functionality into ASCIICaseInsensitiveHash and allow
+    // a HashMap whose keys are type String to perform operations when given a key of type StringView.
+    struct ASCIICaseInsensitiveStringViewHashTranslator {
+    static unsigned hash(StringView key)
+    {
+        if (key.is8Bit())
+            return ASCIICaseInsensitiveHash::hash(key.characters8(), key.length());
+        return ASCIICaseInsensitiveHash::hash(key.characters16(), key.length());
+    }
+
+    static bool equal(const String& a, StringView b)
+    {
+        return equalIgnoringASCIICaseCommon(a, b);
+    }
+    };
+
 }
 
 using WTF::ASCIICaseInsensitiveHash;
index 5f18c5e..82b47f0 100644 (file)
@@ -1,3 +1,43 @@
+2017-05-02  Daniel Bates  <dabates@apple.com>
+
+        Using StringView.split() instead of String.split() in some places
+        https://bugs.webkit.org/show_bug.cgi?id=170925
+
+        Reviewed by Darin Adler.
+
+        Replace some uses of String.split() with StringView.split() (added in r211087) as the latter
+        avoids the need to allocate an intermediary Vector of substrings. Instead StringView.split()
+        returns an iterator for traversing the substrings.
+
+        No functionality changed. So, no new tests.
+
+        * accessibility/AccessibilityObject.cpp: Convert some typedefs to modern C++ using declarations.
+        (WebCore::ASCIICaseInsensitiveStringViewHashTranslator::hash): Added.
+        (WebCore::ASCIICaseInsensitiveStringViewHashTranslator::equal): Added.
+        (WebCore::AccessibilityObject::ariaRoleToWebCoreRole): Modified code to use StringView.split().
+        (WebCore::AccessibilityObject::elementsFromAttribute): Ditto.
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::getElementById): Added.
+        * dom/TreeScope.h:
+        * html/LinkRelAttribute.cpp:
+        (WebCore::LinkRelAttribute::LinkRelAttribute): Modified code to use StringView.split().
+        * html/parser/XSSAuditor.cpp:
+        (WebCore::semicolonSeparatedValueContainsJavaScriptURL): Ditto.
+        * platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm:
+        (WebCore::CDMPrivateMediaSourceAVFObjC::createSession): Ditto.
+        * platform/network/CacheValidation.cpp:
+        (WebCore::collectVaryingRequestHeaders): Simplify code by using the String.split(UChar, Vector<String>&) overload.
+        * svg/SVGAnimationElement.cpp:
+        (WebCore::parseKeyTimes): Modified code to use StringView.split().
+        * svg/SVGToOTFFontConversion.cpp:
+        (WebCore::SVGToOTFFontConverter::SVGToOTFFontConverter): Ditto.
+        * testing/Internals.cpp:
+        (WebCore::Internals::setMediaSessionRestrictions): Ditto.
+        (WebCore::Internals::setMediaElementRestrictions): Ditto.
+        (WebCore::Internals::setAudioContextRestrictions): Ditto.
+        (WebCore::Internals::setPageMuted): Ditto.
+        * testing/Internals.h:
+
 2017-05-02  Gwang Yoon Hwang  <yoon@igalia.com>
 
         [GTK] Drop coordinated surfaces from the compositing thread as soon as possible
index e90c5d9..f02f6b4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2008-2009, 2011, 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -74,6 +74,7 @@
 #include <wtf/NeverDestroyed.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringView.h>
 #include <wtf/text/WTFString.h>
 #include <wtf/unicode/CharacterNames.h>
 
@@ -2132,8 +2133,8 @@ AccessibilityObject* AccessibilityObject::firstAnonymousBlockChild() const
     return nullptr;
 }
 
-typedef HashMap<String, AccessibilityRole, ASCIICaseInsensitiveHash> ARIARoleMap;
-typedef HashMap<AccessibilityRole, String, DefaultHash<int>::Hash, WTF::UnsignedWithZeroKeyHashTraits<int>> ARIAReverseRoleMap;
+using ARIARoleMap = HashMap<String, AccessibilityRole, ASCIICaseInsensitiveHash>;
+using ARIAReverseRoleMap = HashMap<AccessibilityRole, String, DefaultHash<int>::Hash, WTF::UnsignedWithZeroKeyHashTraits<int>>;
 
 static ARIARoleMap* gAriaRoleMap = nullptr;
 static ARIAReverseRoleMap* gAriaReverseRoleMap = nullptr;
@@ -2287,17 +2288,11 @@ static ARIAReverseRoleMap& reverseAriaRoleMap()
 AccessibilityRole AccessibilityObject::ariaRoleToWebCoreRole(const String& value)
 {
     ASSERT(!value.isEmpty());
-    
-    Vector<String> roleVector;
-    value.split(' ', roleVector);
-    AccessibilityRole role = UnknownRole;
-    for (const auto& roleName : roleVector) {
-        role = ariaRoleMap().get(roleName);
-        if (role)
+    for (auto roleName : StringView(value).split(' ')) {
+        if (AccessibilityRole role = ariaRoleMap().get<ASCIICaseInsensitiveStringViewHashTranslator>(roleName))
             return role;
     }
-    
-    return role;
+    return UnknownRole;
 }
 
 String AccessibilityObject::computedRoleString() const
@@ -3176,11 +3171,8 @@ void AccessibilityObject::elementsFromAttribute(Vector<Element*>& elements, cons
         return;
 
     idList.replace('\n', ' ');
-    Vector<String> idVector;
-    idList.split(' ', idVector);
-
-    for (const auto& idName : idVector) {
-        if (Element* idElement = treeScope.getElementById(idName))
+    for (auto idName : StringView(idList).split(' ')) {
+        if (auto* idElement = treeScope.getElementById(idName))
             elements.append(idElement);
     }
 }
index cc0e8e3..bf90e34 100644 (file)
@@ -114,6 +114,17 @@ Element* TreeScope::getElementById(const String& elementId) const
     return nullptr;
 }
 
+Element* TreeScope::getElementById(StringView elementId) const
+{
+    if (!m_elementsById)
+        return nullptr;
+
+    if (auto atomicElementId = elementId.toExistingAtomicString())
+        return m_elementsById->getElementById(*atomicElementId, *this);
+
+    return nullptr;
+}
+
 const Vector<Element*>* TreeScope::getAllElementsById(const AtomicString& elementId) const
 {
     if (elementId.isEmpty())
index 954ec71..a5c9f6a 100644 (file)
@@ -56,6 +56,7 @@ public:
 
     WEBCORE_EXPORT Element* getElementById(const AtomicString&) const;
     WEBCORE_EXPORT Element* getElementById(const String&) const;
+    Element* getElementById(StringView) const;
     const Vector<Element*>* getAllElementsById(const AtomicString&) const;
     bool hasElementWithId(const AtomicStringImpl&) const;
     bool containsMultipleElementsWithId(const AtomicString& id) const;
index b76955c..866afd8 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "LinkIconType.h"
 #include "RuntimeEnabledFeatures.h"
+#include <wtf/text/StringView.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -64,9 +65,7 @@ LinkRelAttribute::LinkRelAttribute(const String& rel)
         // Tokenize the rel attribute and set bits based on specific keywords that we find.
         String relCopy = rel;
         relCopy.replace('\n', ' ');
-        Vector<String> list;
-        relCopy.split(' ', list);
-        for (auto& word : list) {
+        for (auto word : StringView(relCopy).split(' ')) {
             if (equalLettersIgnoringASCIICase(word, "stylesheet"))
                 isStyleSheet = true;
             else if (equalLettersIgnoringASCIICase(word, "alternate"))
index f314dd4..8e1bcc8 100644 (file)
@@ -43,6 +43,7 @@
 #include <wtf/ASCIICType.h>
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/text/StringView.h>
 
 namespace WebCore {
 
@@ -238,11 +239,9 @@ static bool isSemicolonSeparatedAttribute(const HTMLToken::Attribute& attribute)
     return threadSafeMatch(attribute.name, SVGNames::valuesAttr);
 }
 
-static bool semicolonSeparatedValueContainsJavaScriptURL(const String& value)
+static bool semicolonSeparatedValueContainsJavaScriptURL(StringView semicolonSeparatedValue)
 {
-    Vector<String> valueList;
-    value.split(';', valueList);
-    for (auto& value : valueList) {
+    for (auto value : semicolonSeparatedValue.split(';')) {
         if (protocolIsJavaScript(value))
             return true;
     }
index 54efec2..fd16878 100644 (file)
@@ -35,6 +35,7 @@
 #import "MediaPlayerPrivateMediaSourceAVFObjC.h"
 #import "WebCoreSystemInterface.h"
 #import <wtf/NeverDestroyed.h>
+#import <wtf/text/StringView.h>
 #import <yarr/RegularExpression.h>
 
 using JSC::Yarr::RegularExpression;
@@ -101,18 +102,16 @@ bool CDMPrivateMediaSourceAVFObjC::supportsMIMEType(const String& mimeType)
 
 std::unique_ptr<CDMSession> CDMPrivateMediaSourceAVFObjC::createSession(CDMSessionClient* client)
 {
-    String keySystem = m_cdm->keySystem();
+    String keySystem = m_cdm->keySystem(); // Local copy for StringView usage
+    StringView keySystemStringView { keySystem };
     ASSERT(validKeySystemRE().match(keySystem) >= 0);
 
-    Vector<String> protocolVersionsStrings;
-    keySystem.substring(16).split(',', false, protocolVersionsStrings);
-
     Vector<int> protocolVersions;
-    for (auto& protocolVersionString : protocolVersionsStrings)
+    for (StringView protocolVersionString : keySystemStringView.substring(16).split(','))
         protocolVersions.append(protocolVersionString.toInt());
 
     std::unique_ptr<CDMSessionMediaSourceAVFObjC> session;
-    if (keySystem.substring(14, 1).toInt() == 3 && CDMSessionAVContentKeySession::isAvailable())
+    if (keySystemStringView.substring(14, 1).toInt() == 3 && CDMSessionAVContentKeySession::isAvailable())
         session = std::make_unique<CDMSessionAVContentKeySession>(protocolVersions, *this, client);
     else
         session = std::make_unique<CDMSessionAVStreamSession>(protocolVersions, *this, client);
index bed20e3..e177a91 100644 (file)
@@ -356,7 +356,7 @@ Vector<std::pair<String, String>> collectVaryingRequestHeaders(const WebCore::Re
     if (varyValue.isEmpty())
         return { };
     Vector<String> varyingHeaderNames;
-    varyValue.split(',', /*allowEmptyEntries*/ false, varyingHeaderNames);
+    varyValue.split(',', varyingHeaderNames);
     Vector<std::pair<String, String>> varyingRequestHeaders;
     varyingRequestHeaders.reserveCapacity(varyingHeaderNames.size());
     for (auto& varyHeaderName : varyingHeaderNames) {
index b1457f4..1f28625 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
  * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
  * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
- * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2017 Apple Inc. All rights reserved.
  * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
  * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved.
@@ -61,18 +61,17 @@ SVGAnimationElement::SVGAnimationElement(const QualifiedName& tagName, Document&
 static void parseKeyTimes(const String& parse, Vector<float>& result, bool verifyOrder)
 {
     result.clear();
-    Vector<String> parseList;
-    parse.split(';', parseList);
-    for (unsigned n = 0; n < parseList.size(); ++n) {
-        String timeString = parseList[n];
+    bool isFirst = true;
+    for (StringView timeString : StringView(parse).split(';')) {
         bool ok;
-        float time = timeString.toFloat(&ok);
+        float time = timeString.toFloat(ok);
         if (!ok || time < 0 || time > 1)
             goto fail;
         if (verifyOrder) {
-            if (!n) {
+            if (isFirst) {
                 if (time)
                     goto fail;
+                isFirst = false;
             } else if (time < result.last())
                 goto fail;
         }
index c708c5a..32710ea 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -39,6 +39,7 @@
 #include "SVGPathParser.h"
 #include "SVGPathStringSource.h"
 #include "SVGVKernElement.h"
+#include <wtf/text/StringView.h>
 
 namespace WebCore {
 
@@ -1471,22 +1472,21 @@ SVGToOTFFontConverter::SVGToOTFFontConverter(const SVGFontElement& fontElement)
 
     // FIXME: Handle commas.
     if (m_fontFaceElement) {
-        Vector<String> segments;
-        m_fontFaceElement->attributeWithoutSynchronization(SVGNames::font_weightAttr).string().split(' ', segments);
-        for (auto& segment : segments) {
+        auto& fontWeightAttribute = m_fontFaceElement->attributeWithoutSynchronization(SVGNames::font_weightAttr);
+        for (auto segment : StringView(fontWeightAttribute).split(' ')) {
             if (equalLettersIgnoringASCIICase(segment, "bold")) {
                 m_weight = 7;
                 break;
             }
             bool ok;
-            int value = segment.toInt(&ok);
+            int value = segment.toInt(ok);
             if (ok && value >= 0 && value < 1000) {
                 m_weight = (value + 50) / 100;
                 break;
             }
         }
-        m_fontFaceElement->attributeWithoutSynchronization(SVGNames::font_styleAttr).string().split(' ', segments);
-        for (auto& segment : segments) {
+        auto& fontStyleAttribute = m_fontFaceElement->attributeWithoutSynchronization(SVGNames::font_styleAttr);
+        for (auto segment : StringView(fontStyleAttribute).split(' ')) {
             if (equalLettersIgnoringASCIICase(segment, "italic") || equalLettersIgnoringASCIICase(segment, "oblique")) {
                 m_italic = true;
                 break;
index 2c5462e..4862e46 100644 (file)
 #include <runtime/JSCJSValue.h>
 #include <wtf/MemoryPressureHandler.h>
 #include <wtf/MonotonicTime.h>
-#include <wtf/text/CString.h>
 #include <wtf/text/StringBuffer.h>
 #include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringView.h>
 
 #if ENABLE(INPUT_TYPE_COLOR)
 #include "ColorChooser.h"
@@ -3242,7 +3242,7 @@ static PlatformMediaSession::MediaType mediaTypeFromString(const String& mediaTy
     return PlatformMediaSession::None;
 }
 
-ExceptionOr<void> Internals::setMediaSessionRestrictions(const String& mediaTypeString, const String& restrictionsString)
+ExceptionOr<void> Internals::setMediaSessionRestrictions(const String& mediaTypeString, StringView restrictionsString)
 {
     PlatformMediaSession::MediaType mediaType = mediaTypeFromString(mediaTypeString);
     if (mediaType == PlatformMediaSession::None)
@@ -3253,9 +3253,7 @@ ExceptionOr<void> Internals::setMediaSessionRestrictions(const String& mediaType
 
     restrictions = PlatformMediaSessionManager::NoRestrictions;
 
-    Vector<String> restrictionsArray;
-    restrictionsString.split(',', false, restrictionsArray);
-    for (auto& restrictionString : restrictionsArray) {
+    for (StringView restrictionString : restrictionsString.split(',')) {
         if (equalLettersIgnoringASCIICase(restrictionString, "concurrentplaybacknotpermitted"))
             restrictions |= PlatformMediaSessionManager::ConcurrentPlaybackNotPermitted;
         if (equalLettersIgnoringASCIICase(restrictionString, "backgroundprocessplaybackrestricted"))
@@ -3300,16 +3298,14 @@ ExceptionOr<String> Internals::mediaSessionRestrictions(const String& mediaTypeS
     return builder.toString();
 }
 
-void Internals::setMediaElementRestrictions(HTMLMediaElement& element, const String& restrictionsString)
+void Internals::setMediaElementRestrictions(HTMLMediaElement& element, StringView restrictionsString)
 {
     MediaElementSession::BehaviorRestrictions restrictions = element.mediaSession().behaviorRestrictions();
     element.mediaSession().removeBehaviorRestriction(restrictions);
 
     restrictions = MediaElementSession::NoRestrictions;
 
-    Vector<String> restrictionsArray;
-    restrictionsString.split(',', false, restrictionsArray);
-    for (auto& restrictionString : restrictionsArray) {
+    for (StringView restrictionString : restrictionsString.split(',')) {
         if (equalLettersIgnoringASCIICase(restrictionString, "norestrictions"))
             restrictions |= MediaElementSession::NoRestrictions;
         if (equalLettersIgnoringASCIICase(restrictionString, "requireusergestureforload"))
@@ -3429,16 +3425,14 @@ void Internals::sendMediaControlEvent(MediaControlEvent event)
 
 #if ENABLE(WEB_AUDIO)
 
-void Internals::setAudioContextRestrictions(AudioContext& context, const String& restrictionsString)
+void Internals::setAudioContextRestrictions(AudioContext& context, StringView restrictionsString)
 {
     AudioContext::BehaviorRestrictions restrictions = context.behaviorRestrictions();
     context.removeBehaviorRestriction(restrictions);
 
     restrictions = AudioContext::NoRestrictions;
 
-    Vector<String> restrictionsArray;
-    restrictionsString.split(',', false, restrictionsArray);
-    for (auto& restrictionString : restrictionsArray) {
+    for (StringView restrictionString : restrictionsString.split(',')) {
         if (equalLettersIgnoringASCIICase(restrictionString, "norestrictions"))
             restrictions |= AudioContext::NoRestrictions;
         if (equalLettersIgnoringASCIICase(restrictionString, "requireusergestureforaudiostart"))
@@ -3517,19 +3511,17 @@ ExceptionOr<String> Internals::pageOverlayLayerTreeAsText(unsigned short flags)
     return MockPageOverlayClient::singleton().layerTreeAsText(document->frame()->mainFrame(), toLayerTreeFlags(flags));
 }
 
-void Internals::setPageMuted(const String& states)
+void Internals::setPageMuted(StringView statesString)
 {
     Document* document = contextDocument();
     if (!document)
         return;
 
     WebCore::MediaProducer::MutedStateFlags state = MediaProducer::NoneMuted;
-    Vector<String> stateString;
-    states.split(',', false, stateString);
-    for (auto& muteString : stateString) {
-        if (equalLettersIgnoringASCIICase(muteString, "audio"))
+    for (StringView stateString : statesString.split(',')) {
+        if (equalLettersIgnoringASCIICase(stateString, "audio"))
             state |= MediaProducer::AudioIsMuted;
-        if (equalLettersIgnoringASCIICase(muteString, "capturedevices"))
+        if (equalLettersIgnoringASCIICase(stateString, "capturedevices"))
             state |= MediaProducer::CaptureDevicesAreMuted;
     }
 
index d7cd960..ba8a215 100644 (file)
@@ -469,9 +469,9 @@ public:
     void endMediaSessionInterruption(const String&);
     void applicationDidEnterForeground() const;
     void applicationWillEnterBackground() const;
-    ExceptionOr<void> setMediaSessionRestrictions(const String& mediaType, const String& restrictions);
+    ExceptionOr<void> setMediaSessionRestrictions(const String& mediaType, StringView restrictionsString);
     ExceptionOr<String> mediaSessionRestrictions(const String& mediaType) const;
-    void setMediaElementRestrictions(HTMLMediaElement&, const String& restrictions);
+    void setMediaElementRestrictions(HTMLMediaElement&, StringView restrictionsString);
     ExceptionOr<void> postRemoteControlCommand(const String&, float argument);
     bool elementIsBlockingDisplaySleep(HTMLMediaElement&) const;
 #endif
@@ -491,7 +491,7 @@ public:
 #endif
 
 #if ENABLE(WEB_AUDIO)
-    void setAudioContextRestrictions(AudioContext&, const String& restrictions);
+    void setAudioContextRestrictions(AudioContext&, StringView restrictionsString);
 #endif
 
     void simulateSystemSleep() const;
@@ -501,7 +501,7 @@ public:
     ExceptionOr<Ref<MockPageOverlay>> installMockPageOverlay(PageOverlayType);
     ExceptionOr<String> pageOverlayLayerTreeAsText(unsigned short flags) const;
 
-    void setPageMuted(const String&);
+    void setPageMuted(StringView);
     String pageMediaState();
 
     void setPageDefersLoading(bool);