From 641943944d1c6c148815f42f1e9a196d6cf5d925 Mon Sep 17 00:00:00 2001 From: Martin Hurton Date: Tue, 8 May 2012 13:30:13 +0200 Subject: [PATCH] Simplify encoder's loop --- src/encoder.hpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/encoder.hpp b/src/encoder.hpp index 4784ac5f..c78b3e35 100644 --- a/src/encoder.hpp +++ b/src/encoder.hpp @@ -69,11 +69,11 @@ namespace zmq unsigned char *buffer = !*data_ ? buf : *data_; size_t buffersize = !*data_ ? bufsize : *size_; - size_t pos = 0; if (offset_) *offset_ = -1; - while (true) { + size_t pos = 0; + while (pos < buffersize) { // If there are no more data to return, run the state machine. // If there are still no data, return what we already have @@ -85,11 +85,8 @@ namespace zmq if (offset_ && *offset_ == -1) *offset_ = static_cast (pos); - if (!(static_cast (this)->*next) ()) { - *data_ = buffer; - *size_ = pos; - return; - } + if (!(static_cast (this)->*next) ()) + break; } // If there are no data in the buffer yet and we are able to @@ -116,12 +113,10 @@ namespace zmq pos += to_copy; write_pos += to_copy; to_write -= to_copy; - if (pos == buffersize) { - *data_ = buffer; - *size_ = pos; - return; - } } + + *data_ = buffer; + *size_ = pos; } protected: