Commit d0875482 authored by Ian Barber's avatar Ian Barber

Merge pull request #338 from hurtonm/code_cleanup

Simplify encoder's loop
parents 80e8baaf 64194394
...@@ -69,11 +69,11 @@ namespace zmq ...@@ -69,11 +69,11 @@ namespace zmq
unsigned char *buffer = !*data_ ? buf : *data_; unsigned char *buffer = !*data_ ? buf : *data_;
size_t buffersize = !*data_ ? bufsize : *size_; size_t buffersize = !*data_ ? bufsize : *size_;
size_t pos = 0;
if (offset_) if (offset_)
*offset_ = -1; *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 no more data to return, run the state machine.
// If there are still no data, return what we already have // If there are still no data, return what we already have
...@@ -85,11 +85,8 @@ namespace zmq ...@@ -85,11 +85,8 @@ namespace zmq
if (offset_ && *offset_ == -1) if (offset_ && *offset_ == -1)
*offset_ = static_cast <int> (pos); *offset_ = static_cast <int> (pos);
if (!(static_cast <T*> (this)->*next) ()) { if (!(static_cast <T*> (this)->*next) ())
*data_ = buffer; break;
*size_ = pos;
return;
}
} }
// If there are no data in the buffer yet and we are able to // If there are no data in the buffer yet and we are able to
...@@ -116,12 +113,10 @@ namespace zmq ...@@ -116,12 +113,10 @@ namespace zmq
pos += to_copy; pos += to_copy;
write_pos += to_copy; write_pos += to_copy;
to_write -= to_copy; to_write -= to_copy;
if (pos == buffersize) {
*data_ = buffer;
*size_ = pos;
return;
}
} }
*data_ = buffer;
*size_ = pos;
} }
protected: protected:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment