Skip to content

Commit

Permalink
Remove need for string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Jan 3, 2024
1 parent bc3b61e commit 4ce10a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 7 additions & 8 deletions shuffle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -72,9 +74,6 @@ std::tuple<std::string, std::string> 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";

Expand Down Expand Up @@ -125,10 +124,10 @@ std::tuple<std::string, std::string> 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();
Expand Down
3 changes: 1 addition & 2 deletions shuffle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <tuple>
#include <variant>
#include <string>
#include <string_view>
#include <vector>
#include <algorithm>
#include <random>
Expand All @@ -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;
Expand Down

0 comments on commit 4ce10a6

Please sign in to comment.