Use StringView more in DOMFileSystem code
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Sep 2017 04:55:29 +0000 (04:55 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Sep 2017 04:55:29 +0000 (04:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176347

Reviewed by Darin Adler.

* Modules/entriesapi/DOMFileSystem.cpp:
(WebCore::resolveRelativeVirtualPath):
(WebCore::DOMFileSystem::evaluatePath):
* platform/FileSystem.h:
* platform/glib/FileSystemGlib.cpp:
(WebCore::pathByAppendingComponents):
* platform/posix/FileSystemPOSIX.cpp:
(WebCore::pathByAppendingComponents):
* platform/win/FileSystemWin.cpp:
(WebCore::pathByAppendingComponents):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp
Source/WebCore/platform/FileSystem.h
Source/WebCore/platform/glib/FileSystemGlib.cpp
Source/WebCore/platform/posix/FileSystemPOSIX.cpp
Source/WebCore/platform/win/FileSystemWin.cpp

index 9b9cb1e..97c28b0 100644 (file)
@@ -1,3 +1,21 @@
+2017-09-04  Chris Dumez  <cdumez@apple.com>
+
+        Use StringView more in DOMFileSystem code
+        https://bugs.webkit.org/show_bug.cgi?id=176347
+
+        Reviewed by Darin Adler.
+
+        * Modules/entriesapi/DOMFileSystem.cpp:
+        (WebCore::resolveRelativeVirtualPath):
+        (WebCore::DOMFileSystem::evaluatePath):
+        * platform/FileSystem.h:
+        * platform/glib/FileSystemGlib.cpp:
+        (WebCore::pathByAppendingComponents):
+        * platform/posix/FileSystemPOSIX.cpp:
+        (WebCore::pathByAppendingComponents):
+        * platform/win/FileSystemWin.cpp:
+        (WebCore::pathByAppendingComponents):
+
 2017-09-04  Eric Carlson  <eric.carlson@apple.com>
 
         Switch HTMLMediaElement to release logging
index 7fbe681..a719b5f 100644 (file)
@@ -174,15 +174,17 @@ static ExceptionOr<String> validatePathIsExpectedType(const String& fullPath, St
 }
 
 // https://wicg.github.io/entries-api/#resolve-a-relative-path
-static String resolveRelativeVirtualPath(const String& baseVirtualPath, StringView relativeVirtualPath)
+static String resolveRelativeVirtualPath(StringView baseVirtualPath, StringView relativeVirtualPath)
 {
     ASSERT(baseVirtualPath[0] == '/');
     if (relativeVirtualPath[0] == '/')
-        return relativeVirtualPath.length() == 1 ? relativeVirtualPath.toString() : resolveRelativeVirtualPath(ASCIILiteral("/"), relativeVirtualPath.substring(1));
+        return relativeVirtualPath.length() == 1 ? relativeVirtualPath.toString() : resolveRelativeVirtualPath("/", relativeVirtualPath.substring(1));
 
-    auto virtualPathSegments = baseVirtualPath.split('/');
-    auto relativePathSegments = relativeVirtualPath.split('/');
-    for (auto segment : relativePathSegments) {
+    Vector<StringView> virtualPathSegments;
+    for (auto segment : baseVirtualPath.split('/'))
+        virtualPathSegments.append(segment);
+
+    for (auto segment : relativeVirtualPath.split('/')) {
         ASSERT(!segment.isEmpty());
         if (segment == ".")
             continue;
@@ -191,7 +193,7 @@ static String resolveRelativeVirtualPath(const String& baseVirtualPath, StringVi
                 virtualPathSegments.removeLast();
             continue;
         }
-        virtualPathSegments.append(segment.toStringWithoutCopying());
+        virtualPathSegments.append(segment);
     }
 
     if (virtualPathSegments.isEmpty())
@@ -209,10 +211,9 @@ static String resolveRelativeVirtualPath(const String& baseVirtualPath, StringVi
 String DOMFileSystem::evaluatePath(StringView virtualPath)
 {
     ASSERT(virtualPath[0] == '/');
-    auto components = virtualPath.split('/');
 
-    Vector<String> resolvedComponents;
-    for (auto component : components) {
+    Vector<StringView> resolvedComponents;
+    for (auto component : virtualPath.split('/')) {
         if (component == ".")
             continue;
         if (component == "..") {
@@ -220,7 +221,7 @@ String DOMFileSystem::evaluatePath(StringView virtualPath)
                 resolvedComponents.removeLast();
             continue;
         }
-        resolvedComponents.append(component.toStringWithoutCopying());
+        resolvedComponents.append(component);
     }
 
     return pathByAppendingComponents(m_rootPath, resolvedComponents);
index ffe3e4d..6085d17 100644 (file)
@@ -104,7 +104,7 @@ WEBCORE_EXPORT std::optional<FileMetadata> fileMetadata(const String& path);
 WEBCORE_EXPORT std::optional<FileMetadata> fileMetadataFollowingSymlinks(const String& path);
 bool fileIsDirectory(const String&, ShouldFollowSymbolicLinks);
 WEBCORE_EXPORT String pathByAppendingComponent(const String& path, const String& component);
-String pathByAppendingComponents(const String& path, const Vector<String>& components);
+String pathByAppendingComponents(StringView path, const Vector<StringView>& components);
 String lastComponentOfPathIgnoringTrailingSlash(const String& path);
 WEBCORE_EXPORT bool makeAllDirectories(const String& path);
 String homeDirectoryPath();
index b88445b..932e83f 100644 (file)
@@ -207,7 +207,7 @@ String pathByAppendingComponent(const String& path, const String& component)
     return path + G_DIR_SEPARATOR_S + component;
 }
 
-String pathByAppendingComponents(const String& path, const Vector<String>& components)
+String pathByAppendingComponents(StringView path, const Vector<StringView>& components)
 {
     StringBuilder builder;
     builder.append(path);
index 659ff9f..de9a4a6 100644 (file)
@@ -299,7 +299,7 @@ String pathByAppendingComponent(const String& path, const String& component)
     return path + "/" + component;
 }
 
-String pathByAppendingComponents(const String& path, const Vector<String>& components)
+String pathByAppendingComponents(StringView path, const Vector<StringView>& components)
 {
     StringBuilder builder;
     builder.append(path);
index c77a92f..3b6e221 100644 (file)
@@ -263,7 +263,7 @@ String pathByAppendingComponent(const String& path, const String& component)
     return String::adopt(WTFMove(buffer));
 }
 
-String pathByAppendingComponents(const String& path, const Vector<String>& components)
+String pathByAppendingComponents(StringView path, const Vector<StringView>& components)
 {
     String result = path;
     for (auto& component : components)