summaryrefslogtreecommitdiff
path: root/zen/serialize.h
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2023-06-20 07:46:53 -0400
committerB. Stack <bgstack15@gmail.com>2023-06-20 07:46:53 -0400
commitf76994f1fb3e25c4563c9d8afce6bbc86701d1d2 (patch)
treeb39389163603195a0169af57712eb0765e5c11f4 /zen/serialize.h
parentadd upstream 12.3 (diff)
downloadFreeFileSync-f76994f1fb3e25c4563c9d8afce6bbc86701d1d2.tar.gz
FreeFileSync-f76994f1fb3e25c4563c9d8afce6bbc86701d1d2.tar.bz2
FreeFileSync-f76994f1fb3e25c4563c9d8afce6bbc86701d1d2.zip
add upstream 12.412.4
Diffstat (limited to 'zen/serialize.h')
-rw-r--r--zen/serialize.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/zen/serialize.h b/zen/serialize.h
index 8ccecd53..02dcd2b2 100644
--- a/zen/serialize.h
+++ b/zen/serialize.h
@@ -261,11 +261,21 @@ BinContainer unbufferedLoad(Function tryRead /*(void* buffer, size_t bytesToRead
BinContainer buf;
for (;;)
{
- warn_static("don't need zero-initialization!")
- buf.resize(buf.size() + blockSize);
+#ifndef ZEN_HAVE_RESIZE_AND_OVERWRITE
+#error include legacy_compiler.h!
+#endif
+#if ZEN_HAVE_RESIZE_AND_OVERWRITE //permature(?) perf optimization; avoid needless zero-initialization:
+ size_t bytesRead = 0;
+ buf.resize_and_overwrite(buf.size() + blockSize, [&, bufSizeOld = buf.size()](char* rawBuf, size_t /*rawBufSize: caveat: may be larger than what's requested*/)
+ {
+ bytesRead = tryRead(rawBuf + bufSizeOld, blockSize); //throw X; may return short; only 0 means EOF
+ return bufSizeOld + bytesRead;
+ });
+#else
+ buf.resize(buf.size() + blockSize); //needless zero-initialization!
const size_t bytesRead = tryRead(buf.data() + buf.size() - blockSize, blockSize); //throw X; may return short; only 0 means EOF
buf.resize(buf.size() - blockSize + bytesRead); //caveat: unsigned arithmetics
-
+#endif
if (bytesRead == 0) //end of file
{
//caveat: memory consumption of returned string!
bgstack15