From 4ce10a696f76529c7c88e2e0633189885fde70fa Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Wed, 3 Jan 2024 18:44:43 -0500 Subject: [PATCH] Remove need for string_view --- shuffle.cpp | 15 +++++++-------- shuffle.hpp | 3 +-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/shuffle.cpp b/shuffle.cpp index 5909541..aaf25de 100644 --- a/shuffle.cpp +++ b/shuffle.cpp @@ -9,7 +9,9 @@ mmap_handle_t mmap_open(const std::string &file){ throw std::runtime_error("Unable to open " + file); } - mht.file_size = GetFileSize(mht.file_handle, NULL); + LARGE_INTEGER li; + GetFileSizeEx(mht.file_handle, &li); + mht.file_size = li.QuadPart; mht.file_mapping = CreateFileMapping(mht.file_handle, NULL, PAGE_READONLY, 0, 0, NULL); if (mht.file_mapping == NULL) { CloseHandle(mht.file_handle); @@ -72,9 +74,6 @@ std::tuple shuffle(const std::string &src, const std:: mmap_handle_t smht = mmap_open(src); mmap_handle_t tmht = mmap_open(tgt); - std::ifstream tgt_is(tgt); - if (!tgt_is.is_open()) throw std::runtime_error("Cannot open " + tgt); - std::string src_out = src + ".shuffled"; std::string tgt_out = tgt + ".shuffled"; @@ -125,10 +124,10 @@ std::tuple shuffle(const std::string &src, const std:: // std::cout << offsets.size() << std::endl << std::endl; for (size_t i = 0; i < offsets.size(); i++){ - std::string_view slv(offsets[i].src_start, offsets[i].src_end - offsets[i].src_start); - std::string_view tlv(offsets[i].tgt_start, offsets[i].tgt_end - offsets[i].tgt_start); - src_of << slv << "\n"; - tgt_of << tlv << "\n"; + src_of.write(offsets[i].src_start, offsets[i].src_end - offsets[i].src_start); + src_of.write("\n", 1); + tgt_of.write(offsets[i].tgt_start, offsets[i].tgt_end - offsets[i].tgt_start); + tgt_of.write("\n", 1); } src_of.close(); diff --git a/shuffle.hpp b/shuffle.hpp index 421b7e6..434fe4f 100644 --- a/shuffle.hpp +++ b/shuffle.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -25,7 +24,7 @@ typedef struct{ #if defined(_WIN32) || defined(_WIN64) HANDLE file_handle; HANDLE file_mapping; - DWORD file_size; + SIZE_T file_size; #else int fd; off_t file_size;