<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[162921] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/162921">162921</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2014-01-28 00:15:39 -0800 (Tue, 28 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Avoid unnecessary string duplications in FileSystemGtk
https://bugs.webkit.org/show_bug.cgi?id=127469

Reviewed by Martin Robinson.

We are using fileSystemRepresentation() everywhere internally
which returns a CString that always duplicates the string.
Add unescapedFilename() internal helper function that returns a
GUniquePtr and used it everywhere instead of fileSystemRepresentation().

* platform/gtk/FileSystemGtk.cpp:
(WebCore::unescapedFilename):
(WebCore::fileSystemRepresentation):
(WebCore::filenameForDisplay):
(WebCore::fileExists):
(WebCore::deleteFile):
(WebCore::deleteEmptyDirectory):
(WebCore::getFileStat):
(WebCore::getFileSize):
(WebCore::getFileModificationTime):
(WebCore::getFileMetadata):
(WebCore::pathByAppendingComponent):
(WebCore::makeAllDirectories):
(WebCore::pathGetFileName):
(WebCore::directoryName):
(WebCore::listDirectory):
(WebCore::openFile):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgtkFileSystemGtkcpp">trunk/Source/WebCore/platform/gtk/FileSystemGtk.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (162920 => 162921)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-01-28 07:52:01 UTC (rev 162920)
+++ trunk/Source/WebCore/ChangeLog        2014-01-28 08:15:39 UTC (rev 162921)
</span><span class="lines">@@ -1,5 +1,35 @@
</span><span class="cx"> 2014-01-27  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [GTK] Avoid unnecessary string duplications in FileSystemGtk
+        https://bugs.webkit.org/show_bug.cgi?id=127469
+
+        Reviewed by Martin Robinson.
+
+        We are using fileSystemRepresentation() everywhere internally
+        which returns a CString that always duplicates the string.
+        Add unescapedFilename() internal helper function that returns a
+        GUniquePtr and used it everywhere instead of fileSystemRepresentation().
+
+        * platform/gtk/FileSystemGtk.cpp:
+        (WebCore::unescapedFilename):
+        (WebCore::fileSystemRepresentation):
+        (WebCore::filenameForDisplay):
+        (WebCore::fileExists):
+        (WebCore::deleteFile):
+        (WebCore::deleteEmptyDirectory):
+        (WebCore::getFileStat):
+        (WebCore::getFileSize):
+        (WebCore::getFileModificationTime):
+        (WebCore::getFileMetadata):
+        (WebCore::pathByAppendingComponent):
+        (WebCore::makeAllDirectories):
+        (WebCore::pathGetFileName):
+        (WebCore::directoryName):
+        (WebCore::listDirectory):
+        (WebCore::openFile):
+
+2014-01-27  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
</ins><span class="cx">         [GTK] Make webkit_uri_scheme_request_get_web_view() work with CustomProtocols
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=127614
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkFileSystemGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/FileSystemGtk.cpp (162920 => 162921)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/FileSystemGtk.cpp        2014-01-28 07:52:01 UTC (rev 162920)
+++ trunk/Source/WebCore/platform/gtk/FileSystemGtk.cpp        2014-01-28 08:15:39 UTC (rev 162921)
</span><span class="lines">@@ -54,12 +54,23 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static GUniquePtr&lt;char&gt; unescapedFilename(const String&amp; path)
+{
+    if (path.isEmpty())
+        return nullptr;
+#if OS(WINDOWS)
+    return GUniquePtr&lt;char&gt;(g_strdup(path.utf8().data()));
+#else
+    return GUniquePtr&lt;char&gt;(g_uri_unescape_string(path.utf8().data(), nullptr));
+#endif
+}
+
</ins><span class="cx"> CString fileSystemRepresentation(const String&amp; path)
</span><span class="cx"> {
</span><span class="cx"> #if OS(WINDOWS)
</span><span class="cx">     return path.utf8();
</span><span class="cx"> #else
</span><del>-    GUniquePtr&lt;gchar&gt; filename(g_uri_unescape_string(path.utf8().data(), 0));
</del><ins>+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(path);
</ins><span class="cx">     return filename.get();
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="lines">@@ -70,8 +81,11 @@
</span><span class="cx"> #if OS(WINDOWS)
</span><span class="cx">     return string;
</span><span class="cx"> #else
</span><del>-    CString filename = fileSystemRepresentation(string);
-    GUniquePtr&lt;gchar&gt; display(g_filename_to_utf8(filename.data(), 0, 0, 0, 0));
</del><ins>+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(string);
+    if (!filename)
+        return string;
+
+    GUniquePtr&lt;gchar&gt; display(g_filename_to_utf8(filename.get(), -1, nullptr, nullptr, nullptr));
</ins><span class="cx">     if (!display)
</span><span class="cx">         return string;
</span><span class="cx"> 
</span><span class="lines">@@ -81,46 +95,35 @@
</span><span class="cx"> 
</span><span class="cx"> bool fileExists(const String&amp; path)
</span><span class="cx"> {
</span><del>-    bool result = false;
-    CString filename = fileSystemRepresentation(path);
-
-    if (!filename.isNull())
-        result = g_file_test(filename.data(), G_FILE_TEST_EXISTS);
-
-    return result;
</del><ins>+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(path);
+    return filename ? g_file_test(filename.get(), G_FILE_TEST_EXISTS) : false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool deleteFile(const String&amp; path)
</span><span class="cx"> {
</span><del>-    bool result = false;
-    CString filename = fileSystemRepresentation(path);
-
-    if (!filename.isNull())
-        result = g_remove(filename.data()) == 0;
-
-    return result;
</del><ins>+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(path);
+    return filename ? g_remove(filename.get()) != -1 : false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool deleteEmptyDirectory(const String&amp; path)
</span><span class="cx"> {
</span><del>-    bool result = false;
-    CString filename = fileSystemRepresentation(path);
</del><ins>+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(path);
+    return filename ? g_rmdir(filename.get()) != -1 : false;
+}
</ins><span class="cx"> 
</span><del>-    if (!filename.isNull())
-        result = g_rmdir(filename.data()) == 0;
</del><ins>+static bool getFileStat(const String&amp; path, GStatBuf* statBuffer)
+{
+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(path);
+    if (!filename)
+        return false;
</ins><span class="cx"> 
</span><del>-    return result;
</del><ins>+    return g_stat(filename.get(), statBuffer) != -1;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool getFileSize(const String&amp; path, long long&amp; resultSize)
</span><span class="cx"> {
</span><del>-    CString filename = fileSystemRepresentation(path);
-    if (filename.isNull())
-        return false;
-
</del><span class="cx">     GStatBuf statResult;
</span><del>-    gint result = g_stat(filename.data(), &amp;statResult);
-    if (result != 0)
</del><ins>+    if (!getFileStat(path, &amp;statResult))
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     resultSize = statResult.st_size;
</span><span class="lines">@@ -129,55 +132,37 @@
</span><span class="cx"> 
</span><span class="cx"> bool getFileModificationTime(const String&amp; path, time_t&amp; modifiedTime)
</span><span class="cx"> {
</span><del>-    CString filename = fileSystemRepresentation(path);
-    if (filename.isNull())
-        return false;
-
</del><span class="cx">     GStatBuf statResult;
</span><del>-    gint result = g_stat(filename.data(), &amp;statResult);
-    if (result != 0)
</del><ins>+    if (!getFileStat(path, &amp;statResult))
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     modifiedTime = statResult.st_mtime;
</span><span class="cx">     return true;
</span><del>-
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool getFileMetadata(const String&amp; path, FileMetadata&amp; metadata)
</span><span class="cx"> {
</span><del>-    CString filename = fileSystemRepresentation(path);
-    if (filename.isNull())
</del><ins>+    GStatBuf statResult;
+    if (!getFileStat(path, &amp;statResult))
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    struct stat statResult;
-    gint result = g_stat(filename.data(), &amp;statResult);
-    if (result)
-        return false;
-
</del><span class="cx">     metadata.modificationTime = statResult.st_mtime;
</span><span class="cx">     metadata.length = statResult.st_size;
</span><span class="cx">     metadata.type = S_ISDIR(statResult.st_mode) ? FileMetadata::TypeDirectory : FileMetadata::TypeFile;
</span><span class="cx">     return true;
</span><del>-
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> String pathByAppendingComponent(const String&amp; path, const String&amp; component)
</span><span class="cx"> {
</span><span class="cx">     if (path.endsWith(G_DIR_SEPARATOR_S))
</span><span class="cx">         return path + component;
</span><del>-    else
-        return path + G_DIR_SEPARATOR_S + component;
</del><ins>+    return path + G_DIR_SEPARATOR_S + component;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool makeAllDirectories(const String&amp; path)
</span><span class="cx"> {
</span><del>-    CString filename = fileSystemRepresentation(path);
-    if (filename.isNull())
-        return false;
-
-    gint result = g_mkdir_with_parents(filename.data(), S_IRWXU);
-
-    return result == 0;
</del><ins>+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(path);
+    return filename ? g_mkdir_with_parents(filename.get(), S_IRWXU) != -1 : false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> String homeDirectoryPath()
</span><span class="lines">@@ -187,11 +172,11 @@
</span><span class="cx"> 
</span><span class="cx"> String pathGetFileName(const String&amp; pathName)
</span><span class="cx"> {
</span><del>-    if (pathName.isEmpty())
</del><ins>+    GUniquePtr&lt;gchar&gt; tmpFilename = unescapedFilename(pathName);
+    if (!tmpFilename)
</ins><span class="cx">         return pathName;
</span><span class="cx"> 
</span><del>-    CString tmpFilename = fileSystemRepresentation(pathName);
-    GUniquePtr&lt;gchar&gt; baseName(g_path_get_basename(tmpFilename.data()));
</del><ins>+    GUniquePtr&lt;gchar&gt; baseName(g_path_get_basename(tmpFilename.get()));
</ins><span class="cx">     return String::fromUTF8(baseName.get());
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -242,8 +227,11 @@
</span><span class="cx"> 
</span><span class="cx"> String directoryName(const String&amp; path)
</span><span class="cx"> {
</span><del>-    /* No null checking needed */
-    GUniquePtr&lt;char&gt; dirname(g_path_get_dirname(fileSystemRepresentation(path).data()));
</del><ins>+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(path);
+    if (!filename)
+        return String();
+
+    GUniquePtr&lt;char&gt; dirname(g_path_get_dirname(filename.get()));
</ins><span class="cx">     return String::fromUTF8(dirname.get());
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -251,8 +239,11 @@
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;String&gt; entries;
</span><span class="cx"> 
</span><del>-    CString filename = fileSystemRepresentation(path);
-    GUniquePtr&lt;GDir&gt; dir(g_dir_open(filename.data(), 0, nullptr));
</del><ins>+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(path);
+    if (!filename)
+        return entries;
+
+    GUniquePtr&lt;GDir&gt; dir(g_dir_open(filename.get(), 0, nullptr));
</ins><span class="cx">     if (!dir)
</span><span class="cx">         return entries;
</span><span class="cx"> 
</span><span class="lines">@@ -261,7 +252,7 @@
</span><span class="cx">         if (!g_pattern_match_string(pspec.get(), name))
</span><span class="cx">             continue;
</span><span class="cx"> 
</span><del>-        GUniquePtr&lt;gchar&gt; entry(g_build_filename(filename.data(), name, NULL));
</del><ins>+        GUniquePtr&lt;gchar&gt; entry(g_build_filename(filename.get(), name, nullptr));
</ins><span class="cx">         entries.append(filenameToString(entry.get()));
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -282,16 +273,16 @@
</span><span class="cx"> 
</span><span class="cx"> PlatformFileHandle openFile(const String&amp; path, FileOpenMode mode)
</span><span class="cx"> {
</span><del>-    CString fsRep = fileSystemRepresentation(path);
-    if (fsRep.isNull())
</del><ins>+    GUniquePtr&lt;gchar&gt; filename = unescapedFilename(path);
+    if (!filename)
</ins><span class="cx">         return invalidPlatformFileHandle;
</span><span class="cx"> 
</span><del>-    GRefPtr&lt;GFile&gt; file = adoptGRef(g_file_new_for_path(fsRep.data()));
</del><ins>+    GRefPtr&lt;GFile&gt; file = adoptGRef(g_file_new_for_path(filename.get()));
</ins><span class="cx">     GFileIOStream* ioStream = 0;
</span><span class="cx">     if (mode == OpenForRead)
</span><span class="cx">         ioStream = g_file_open_readwrite(file.get(), 0, 0);
</span><span class="cx">     else if (mode == OpenForWrite) {
</span><del>-        if (g_file_test(fsRep.data(), static_cast&lt;GFileTest&gt;(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)))
</del><ins>+        if (g_file_test(filename.get(), static_cast&lt;GFileTest&gt;(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)))
</ins><span class="cx">             ioStream = g_file_open_readwrite(file.get(), 0, 0);
</span><span class="cx">         else
</span><span class="cx">             ioStream = g_file_create_readwrite(file.get(), G_FILE_CREATE_NONE, 0, 0);
</span></span></pre>
</div>
</div>

</body>
</html>