Skip to content

Commit

Permalink
fixed something stupid
Browse files Browse the repository at this point in the history
  • Loading branch information
StanHash committed Dec 3, 2017
1 parent 6e00c80 commit 204cf66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
15 changes: 14 additions & 1 deletion core/binary_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void binary_file::load_from_other(const binary_file &other, unsigned int start,
return; // TODO: throw exception

mData.clear();
mData.reserve(size - start);
mData.reserve(size);

std::copy(
std::next(other.mData.begin(), start),
Expand All @@ -51,6 +51,19 @@ const char* binary_file::cstr_at(int pos) const {
return reinterpret_cast<const char*>(&mData[pos]);
}

void binary_file::combine_with(const binary_file& other) {
// move combination here wouldn't be that useful, since we're dealing with standard raw data
// there's no allocation overhead in copying over moving

data().reserve(size() + other.size());

std::copy(
other.data().begin(),
other.data().end(),
std::back_inserter(data())
);
}

binary_file::byte_t binary_file::read_byte(int& pos) const {
if (pos >= mData.size())
throw std::out_of_range("tried to read byte out of range of data");
Expand Down
2 changes: 2 additions & 0 deletions core/binary_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class binary_file {
std::vector<byte_t>& data() { return mData; }
const std::vector<byte_t>& data() const { return mData; }

void combine_with(const binary_file& other);

template<typename T, int byte_count = sizeof(T)>
T read(int& pos) const;

Expand Down
16 changes: 2 additions & 14 deletions core/section_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,7 @@ void section_data::combine_with(const section_data& other) {
mRelocations.push_back(relocation);
}

data().reserve(size() + other.size());

std::copy(
other.data().begin(),
other.data().end(),
std::back_inserter(data())
);
binary_file::combine_with(other);
}

void section_data::combine_with(section_data&& other) {
Expand All @@ -137,13 +131,7 @@ void section_data::combine_with(section_data&& other) {
mRelocations.push_back(std::move(relocation));
}

data().reserve(size() + other.size());

std::copy(
other.data().begin(),
other.data().end(),
std::back_inserter(data())
);
binary_file::combine_with(other);
}

void section_data::remove_temp_symbols() {
Expand Down

0 comments on commit 204cf66

Please sign in to comment.