<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [SOUP] Add initial implementation of NetworkProcess disk cache"
   href="https://bugs.webkit.org/show_bug.cgi?id=143872#c19">Comment # 19</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [SOUP] Add initial implementation of NetworkProcess disk cache"
   href="https://bugs.webkit.org/show_bug.cgi?id=143872">bug 143872</a>
              from <span class="vcard"><a class="email" href="mailto:cgarcia&#64;igalia.com" title="Carlos Garcia Campos &lt;cgarcia&#64;igalia.com&gt;"> <span class="fn">Carlos Garcia Campos</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=143872#c18">comment #18</a>)
<span class="quote">&gt; Comment on <span class=""><a href="attachment.cgi?id=251543&amp;action=diff" name="attach_251543" title="Updated to use fast malloc/free">attachment 251543</a> <a href="attachment.cgi?id=251543&amp;action=edit" title="Updated to use fast malloc/free">[details]</a></span>
&gt; Updated to use fast malloc/free
&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=251543&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=251543&amp;action=review</a>
&gt; 
&gt; &gt; Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:129
&gt; &gt; +    GRefPtr&lt;SoupBuffer&gt; buffer = adoptGRef(soup_buffer_new(SOUP_MEMORY_TAKE, static_cast&lt;char*&gt;(g_malloc(bufferSize)), bufferSize));
&gt; 
&gt; Here it might be better to use fastMalloc as well.</span >

Right, I forgot we were also allocating memory here.

<span class="quote">&gt; &gt; Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:142
&gt; &gt; +    GRefPtr&lt;SoupBuffer&gt; readBuffer = adoptGRef(soup_buffer_new(SOUP_MEMORY_TAKE, static_cast&lt;char*&gt;(g_malloc(bufferSize)), bufferSize));
&gt; 
&gt; Ditto.</span >

Right.

<span class="quote">&gt; &gt; Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:162
&gt; &gt; +    size_t bytesToRead = bufferSize;
&gt; &gt; +    do {
&gt; &gt; +        // FIXME: implement offset.
&gt; &gt; +        gssize bytesRead = g_input_stream_read(m_inputStream.get(), const_cast&lt;char*&gt;(readBuffer-&gt;data), bytesToRead, nullptr, nullptr);
&gt; &gt; +        if (bytesRead == -1) {
&gt; &gt; +            completionHandler(data, -1);
&gt; &gt; +            return;
&gt; &gt; +        }
&gt; &gt; +
&gt; &gt; +        if (!bytesRead)
&gt; &gt; +            break;
&gt; &gt; +
&gt; &gt; +        ASSERT(bytesRead &gt; 0);
&gt; &gt; +        fillDataFromReadBuffer(readBuffer.get(), static_cast&lt;size_t&gt;(bytesRead), data);
&gt; &gt; +
&gt; &gt; +        pendingBytesToRead = size - data.size();
&gt; &gt; +        bytesToRead = std::min(pendingBytesToRead, readBuffer-&gt;length);
&gt; &gt; +    } while (pendingBytesToRead);
&gt; 
&gt; Sorry I missed this in the first review. I have a quick question about the
&gt; synchronous read case. Why is it better to read chunks of data and
&gt; constantly fill up small buffers? Why not create a buffer the full size of
&gt; the data and only create a single Data object? Couldn't you avoid all of the
&gt; concatenation that way?</span >

Because we don't know the size, NetworkCacheStorage passes std::numeric_limits&lt;size_t&gt;::max() to ensure we read until end of stream. Note that this readSync method is only used for debugging, when a dump.json file is requested to be created by the user, it's not used when retrieving cache resources for loading.

<span class="quote">&gt; Otherwise, I suggest a small rename here for the sake of clarity:
&gt; pendingBytesToRead -&gt; bytesToRead, bytesToRead -&gt; bytesToReadForCurrentChunk.</span ></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>