Use StringView in DOMFileSystem::evaluatePath()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Sep 2017 06:07:09 +0000 (06:07 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Sep 2017 06:07:09 +0000 (06:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176324

Reviewed by Darin Adler.

Use StringView in DOMFileSystem::evaluatePath() for performance.

* Modules/entriesapi/DOMFileSystem.cpp:
(WebCore::resolveRelativeVirtualPath):
(WebCore::DOMFileSystem::evaluatePath):
* Modules/entriesapi/DOMFileSystem.h:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp
Source/WebCore/Modules/entriesapi/DOMFileSystem.h

index 4377ae7..d3303db 100644 (file)
@@ -1,3 +1,17 @@
+2017-09-03  Chris Dumez  <cdumez@apple.com>
+
+        Use StringView in DOMFileSystem::evaluatePath()
+        https://bugs.webkit.org/show_bug.cgi?id=176324
+
+        Reviewed by Darin Adler.
+
+        Use StringView in DOMFileSystem::evaluatePath() for performance.
+
+        * Modules/entriesapi/DOMFileSystem.cpp:
+        (WebCore::resolveRelativeVirtualPath):
+        (WebCore::DOMFileSystem::evaluatePath):
+        * Modules/entriesapi/DOMFileSystem.h:
+
 2017-09-03  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         String#utf8() allocates new CString
index a4b0c93..7fbe681 100644 (file)
@@ -191,7 +191,7 @@ static String resolveRelativeVirtualPath(const String& baseVirtualPath, StringVi
                 virtualPathSegments.removeLast();
             continue;
         }
-        virtualPathSegments.append(segment.toString());
+        virtualPathSegments.append(segment.toStringWithoutCopying());
     }
 
     if (virtualPathSegments.isEmpty())
@@ -206,14 +206,13 @@ static String resolveRelativeVirtualPath(const String& baseVirtualPath, StringVi
 }
 
 // https://wicg.github.io/entries-api/#evaluate-a-path
-String DOMFileSystem::evaluatePath(const String& virtualPath)
+String DOMFileSystem::evaluatePath(StringView virtualPath)
 {
     ASSERT(virtualPath[0] == '/');
     auto components = virtualPath.split('/');
 
     Vector<String> resolvedComponents;
-    resolvedComponents.reserveInitialCapacity(components.size());
-    for (auto& component : components) {
+    for (auto component : components) {
         if (component == ".")
             continue;
         if (component == "..") {
@@ -221,7 +220,7 @@ String DOMFileSystem::evaluatePath(const String& virtualPath)
                 resolvedComponents.removeLast();
             continue;
         }
-        resolvedComponents.uncheckedAppend(component);
+        resolvedComponents.append(component.toStringWithoutCopying());
     }
 
     return pathByAppendingComponents(m_rootPath, resolvedComponents);
index 047a578..9b30d7c 100644 (file)
@@ -67,7 +67,7 @@ public:
 private:
     explicit DOMFileSystem(Ref<File>&&);
 
-    String evaluatePath(const String& virtualPath);
+    String evaluatePath(StringView virtualPath);
     Ref<FileSystemEntry> fileAsEntry(ScriptExecutionContext&);
 
     String m_name;