aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/datafile/datafile.cpp
diff options
context:
space:
mode:
authorvvvv <vvvv@ydb.tech>2023-07-31 18:21:04 +0300
committervvvv <vvvv@ydb.tech>2023-07-31 18:21:04 +0300
commitdec41c40e51aa407edef81a3c566a5a15780fc49 (patch)
tree4f197b596b32f35eca368121f0dff913419da9af /library/cpp/deprecated/datafile/datafile.cpp
parent3ca8b54c96e09eb2b65be7f09675623438d559c7 (diff)
downloadydb-dec41c40e51aa407edef81a3c566a5a15780fc49.tar.gz
YQL-16239 Move purecalc to public
Diffstat (limited to 'library/cpp/deprecated/datafile/datafile.cpp')
-rw-r--r--library/cpp/deprecated/datafile/datafile.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/library/cpp/deprecated/datafile/datafile.cpp b/library/cpp/deprecated/datafile/datafile.cpp
new file mode 100644
index 00000000000..ff93f11c6b7
--- /dev/null
+++ b/library/cpp/deprecated/datafile/datafile.cpp
@@ -0,0 +1,42 @@
+#include "datafile.h"
+
+void TDataFileBase::DoLoad(const char* fname, int loadMode) {
+ Destroy();
+ TFile f(fname, RdOnly);
+ DoLoad(f, loadMode, nullptr, 0);
+}
+
+void TDataFileBase::DoLoad(TFile& f, int loadMode, void* hdrPtr, size_t hdrSize) {
+ if (hdrPtr) {
+ if (loadMode & DLM_EXACT_SIZE && f.GetLength() != (i64)Length)
+ throw yexception() << f.GetName() << " size does not match its header value";
+ } else {
+ Length = f.GetLength();
+ hdrSize = 0;
+ }
+ if ((loadMode & DLM_LD_TYPE_MASK) == DLM_READ) {
+ MemData = TVector<char>(Length);
+ memcpy(MemData.begin(), hdrPtr, hdrSize);
+ f.Load(MemData.begin() + hdrSize, Length - hdrSize);
+ Start = MemData.begin();
+ } else {
+ FileData.init(f);
+ if (FileData.getSize() < Length)
+ throw yexception() << f.GetName() << " is smaller than what its header value says";
+ if ((loadMode & DLM_LD_TYPE_MASK) == DLM_MMAP_PRC)
+ FileData.precharge();
+ Start = (const char*)FileData.getData();
+ }
+}
+
+void TDataFileBase::Destroy() {
+ TVector<char>().swap(MemData);
+ FileData.term();
+ Start = nullptr;
+ Length = 0;
+}
+
+void TDataFileBase::Precharge() const {
+ if (Length && Start == (char*)FileData.getData())
+ FileData.precharge();
+}