Commit 21560cb 1 parent 973b47c commit 21560cb Copy full SHA for 21560cb
File tree 1 file changed +5
-3
lines changed
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -97,23 +97,25 @@ class PubMaster {
97
97
class AlignedBuffer {
98
98
public:
99
99
kj::ArrayPtr<const capnp::word> align (const char *data, const size_t size) {
100
+ size_t word_count = (size + sizeof (capnp::word) - 1 ) / sizeof (capnp::word);
101
+
100
102
// Check if data is already aligned
101
103
if (reinterpret_cast <uintptr_t >(data) % alignof (capnp::word) == 0 ) {
102
- size_t word_count = (size + sizeof (capnp::word) - 1 ) / sizeof (capnp::word);
103
104
return kj::ArrayPtr<const capnp::word>((const capnp::word *)data, word_count);
104
105
}
105
106
106
- // Data is not aligned, perform alignment
107
- size_t word_count = (size + sizeof (capnp::word) - 1 ) / sizeof (capnp::word);
107
+ // Data is not aligned, perform alignment
108
108
if (aligned_buf.size () < word_count) {
109
109
aligned_buf = kj::heapArray<capnp::word>(std::max (word_count, size_t (512 )));
110
110
}
111
111
memcpy (aligned_buf.begin (), data, size);
112
112
return aligned_buf.slice (0 , word_count);
113
113
}
114
+
114
115
inline kj::ArrayPtr<const capnp::word> align (Message *m) {
115
116
return align (m->getData (), m->getSize ());
116
117
}
118
+
117
119
private:
118
120
kj::Array<capnp::word> aligned_buf;
119
121
};
You can’t perform that action at this time.
0 commit comments