Skip to content

Commit c92afb6

Browse files
committed
Problem: message_t::operator== is absurdly inefficient and constructs temporary copies of both operands
Solution: implement operator== using memcmp instead
1 parent 438bad2 commit c92afb6

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

zmq.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,10 @@ namespace zmq
393393

394394
inline bool operator==(const message_t &other) const ZMQ_NOTHROW
395395
{
396+
size_t my_size = size ();
396397
if (size () != other.size ())
397398
return false;
398-
const std::string a(data<char>(), size());
399-
const std::string b(other.data<char>(), other.size());
400-
return a == b;
399+
return 0 == memcmp (data (), other.data (), my_size);
401400
}
402401

403402
inline bool operator!=(const message_t &other) const ZMQ_NOTHROW

0 commit comments

Comments
 (0)