From d1b0909894a302540f979d904dd378af1cad620c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 15 Apr 2016 15:11:34 +0200 Subject: BinaryCacheStore::readFile(): Return a shared_ptr to a string This allows readFile() to indicate that a file doesn't exist, and might eliminate some large string copying. --- src/libstore/download.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/libstore/download.cc') diff --git a/src/libstore/download.cc b/src/libstore/download.cc index 7277751b48e7..8cd3ad741e10 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -29,7 +29,7 @@ std::string resolveUri(const std::string & uri) struct CurlDownloader : public Downloader { CURL * curl; - string data; + ref data; string etag, status, expectedETag; struct curl_slist * requestHeaders; @@ -41,7 +41,7 @@ struct CurlDownloader : public Downloader size_t writeCallback(void * contents, size_t size, size_t nmemb) { size_t realSize = size * nmemb; - data.append((char *) contents, realSize); + data->append((char *) contents, realSize); return realSize; } @@ -110,6 +110,7 @@ struct CurlDownloader : public Downloader } CurlDownloader() + : data(make_ref()) { requestHeaders = 0; @@ -156,7 +157,7 @@ struct CurlDownloader : public Downloader curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); } - data.clear(); + data->clear(); if (requestHeaders) { curl_slist_free_all(requestHeaders); @@ -269,7 +270,7 @@ Path Downloader::downloadCached(ref store, const string & url_, bool unpa auto res = download(url, options); if (!res.cached) - storePath = store->addTextToStore(name, res.data, PathSet(), false); + storePath = store->addTextToStore(name, *res.data, PathSet(), false); assert(!storePath.empty()); replaceSymlink(storePath, fileLink); -- cgit 1.4.1