Skip to content

Commit 204cf66

Browse files
committed
fixed something stupid
1 parent 6e00c80 commit 204cf66

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

core/binary_file.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void binary_file::load_from_other(const binary_file &other, unsigned int start,
2424
return; // TODO: throw exception
2525

2626
mData.clear();
27-
mData.reserve(size - start);
27+
mData.reserve(size);
2828

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

54+
void binary_file::combine_with(const binary_file& other) {
55+
// move combination here wouldn't be that useful, since we're dealing with standard raw data
56+
// there's no allocation overhead in copying over moving
57+
58+
data().reserve(size() + other.size());
59+
60+
std::copy(
61+
other.data().begin(),
62+
other.data().end(),
63+
std::back_inserter(data())
64+
);
65+
}
66+
5467
binary_file::byte_t binary_file::read_byte(int& pos) const {
5568
if (pos >= mData.size())
5669
throw std::out_of_range("tried to read byte out of range of data");

core/binary_file.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class binary_file {
2727
std::vector<byte_t>& data() { return mData; }
2828
const std::vector<byte_t>& data() const { return mData; }
2929

30+
void combine_with(const binary_file& other);
31+
3032
template<typename T, int byte_count = sizeof(T)>
3133
T read(int& pos) const;
3234

core/section_data.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,7 @@ void section_data::combine_with(const section_data& other) {
108108
mRelocations.push_back(relocation);
109109
}
110110

111-
data().reserve(size() + other.size());
112-
113-
std::copy(
114-
other.data().begin(),
115-
other.data().end(),
116-
std::back_inserter(data())
117-
);
111+
binary_file::combine_with(other);
118112
}
119113

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

140-
data().reserve(size() + other.size());
141-
142-
std::copy(
143-
other.data().begin(),
144-
other.data().end(),
145-
std::back_inserter(data())
146-
);
134+
binary_file::combine_with(other);
147135
}
148136

149137
void section_data::remove_temp_symbols() {

0 commit comments

Comments
 (0)