about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-15T13·11+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-15T13·39+0200
commitd1b0909894a302540f979d904dd378af1cad620c (patch)
tree691ec2d838e4449897549a537145971d9b12a3d5 /src/libutil
parent99851c6f06c80fe2222c5e5fcef963804e907170 (diff)
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.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/compression.cc6
-rw-r--r--src/libutil/compression.hh4
2 files changed, 6 insertions, 4 deletions
diff --git a/src/libutil/compression.cc b/src/libutil/compression.cc
index a3fa0dab737b..b047d305cfa6 100644
--- a/src/libutil/compression.cc
+++ b/src/libutil/compression.cc
@@ -55,7 +55,7 @@ std::string compressXZ(const std::string & in)
     }
 }
 
-std::string decompressXZ(const std::string & in)
+ref<std::string> decompressXZ(const std::string & in)
 {
     LzmaStream strm;
 
@@ -66,7 +66,7 @@ std::string decompressXZ(const std::string & in)
 
     lzma_action action = LZMA_RUN;
     uint8_t outbuf[BUFSIZ];
-    string res;
+    ref<std::string> res = make_ref<std::string>();
     strm().next_in = (uint8_t *) in.c_str();
     strm().avail_in = in.size();
     strm().next_out = outbuf;
@@ -80,7 +80,7 @@ std::string decompressXZ(const std::string & in)
         lzma_ret ret = lzma_code(&strm(), action);
 
         if (strm().avail_out == 0 || ret == LZMA_STREAM_END) {
-            res.append((char *) outbuf, sizeof(outbuf) - strm().avail_out);
+            res->append((char *) outbuf, sizeof(outbuf) - strm().avail_out);
             strm().next_out = outbuf;
             strm().avail_out = sizeof(outbuf);
         }
diff --git a/src/libutil/compression.hh b/src/libutil/compression.hh
index eb1697fc4aa4..79a796db7756 100644
--- a/src/libutil/compression.hh
+++ b/src/libutil/compression.hh
@@ -1,11 +1,13 @@
 #pragma once
 
+#include "ref.hh"
+
 #include <string>
 
 namespace nix {
 
 std::string compressXZ(const std::string & in);
 
-std::string decompressXZ(const std::string & in);
+ref<std::string> decompressXZ(const std::string & in);
 
 }