1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 23:11:16 +02:00

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.
This commit is contained in:
Eelco Dolstra 2016-04-15 15:11:34 +02:00
parent 99851c6f06
commit d1b0909894
11 changed files with 52 additions and 28 deletions

View file

@ -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);
}