Skip to content

Commit cff3a46

Browse files
committed
Problem: Performance of message_t construction can be improved
Solution: Use std::copy instead of a raw loop and fix a conversion warning
1 parent 5c95a07 commit cff3a46

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

zmq.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,14 @@ class message_t
249249

250250
template<typename T> message_t(T first, T last) : msg()
251251
{
252-
typedef typename std::iterator_traits<T>::difference_type size_type;
253252
typedef typename std::iterator_traits<T>::value_type value_t;
254253

255-
size_type const size_ = std::distance(first, last) * sizeof(value_t);
254+
assert(std::distance(first, last) >= 0);
255+
size_t const size_ = static_cast<size_t>(std::distance(first, last)) * sizeof(value_t);
256256
int const rc = zmq_msg_init_size(&msg, size_);
257257
if (rc != 0)
258258
throw error_t();
259-
value_t *dest = data<value_t>();
260-
while (first != last) {
261-
*dest = *first;
262-
++dest;
263-
++first;
264-
}
259+
std::copy(first, last, data<value_t>());
265260
}
266261

267262
message_t(const void *data_, size_t size_)

0 commit comments

Comments
 (0)