summaryrefslogtreecommitdiff
path: root/zen/serialize.h
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2023-11-27 10:33:00 -0500
committerB. Stack <bgstack15@gmail.com>2023-11-27 10:33:00 -0500
commit2e61b9b6258f29c03cb3b0da48282f3a87590702 (patch)
tree2be66dfaf965d246ea2df6248c7890208887e6bb /zen/serialize.h
parentadd upstream 13.1 (diff)
downloadFreeFileSync-13.2.tar.gz
FreeFileSync-13.2.tar.bz2
FreeFileSync-13.2.zip
add upstream 13.213.2
Diffstat (limited to 'zen/serialize.h')
-rw-r--r--zen/serialize.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/zen/serialize.h b/zen/serialize.h
index f3e4f7ff..82ea9971 100644
--- a/zen/serialize.h
+++ b/zen/serialize.h
@@ -260,6 +260,10 @@ BinContainer unbufferedLoad(Function tryRead /*(void* buffer, size_t bytesToRead
BinContainer buf;
for (;;)
{
+#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*/)
//permature(?) perf optimization; avoid needless zero-initialization:
@@ -267,6 +271,11 @@ BinContainer unbufferedLoad(Function tryRead /*(void* buffer, size_t bytesToRead
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