Skip to content

Commit 3b41ae6

Browse files
Merge pull request #19 from thomasisensee/move-allocation
Move allocation
2 parents 51b1d30 + 0874fb4 commit 3b41ae6

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

include/ndtbl/axis.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <algorithm>
66
#include <cstddef>
7+
#include <iterator>
78
#include <stdexcept>
89
#include <utility>
910
#include <vector>

include/ndtbl/field_group.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
#include "ndtbl/payload.hpp"
55

66
#include <algorithm>
7+
#include <array>
78
#include <cstddef>
89
#include <cstdint>
10+
#include <iterator>
911
#include <memory>
1012
#include <stdexcept>
1113
#include <string>
14+
#include <utility>
1215
#include <vector>
1316

1417
namespace ndtbl {

include/ndtbl/io.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
#include "ndtbl/detail/mapped_payload.hpp"
55
#include "ndtbl/runtime_field_group.hpp"
66

7+
#include <array>
8+
#include <cstddef>
9+
#include <cstdint>
710
#include <fstream>
11+
#include <memory>
12+
#include <ostream>
813
#include <stdexcept>
914
#include <string>
15+
#include <utility>
1016
#include <vector>
1117

1218
namespace ndtbl {
@@ -177,8 +183,9 @@ read_group(const std::string& path)
177183
PayloadView<float>(payload_owner.get(), layout.value_count),
178184
payload_owner));
179185
#else
180-
const std::vector<float> values =
181-
detail::read_payload<float>(is, value_count);
186+
// Keep this non-const so the payload buffer can be moved into the
187+
// read-only FieldGroup storage instead of copied during load.
188+
std::vector<float> values = detail::read_payload<float>(is, value_count);
182189
return RuntimeFieldGroup<Dim>(
183190
FieldGroup<float, Dim>(grid, metadata.field_names, std::move(values)));
184191
#endif
@@ -195,8 +202,9 @@ read_group(const std::string& path)
195202
PayloadView<double>(payload_owner.get(), layout.value_count),
196203
payload_owner));
197204
#else
198-
const std::vector<double> values =
199-
detail::read_payload<double>(is, value_count);
205+
// Keep this non-const so the payload buffer can be moved into the
206+
// read-only FieldGroup storage instead of copied during load.
207+
std::vector<double> values = detail::read_payload<double>(is, value_count);
200208
return RuntimeFieldGroup<Dim>(
201209
FieldGroup<double, Dim>(grid, metadata.field_names, std::move(values)));
202210
#endif

0 commit comments

Comments
 (0)