Merge pull request #338 from hurtonm/code_cleanup

Simplify encoder's loop
This commit is contained in:
Ian Barber 2012-05-08 06:41:22 -07:00
commit d087548286

View File

@ -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 <int> (pos);
if (!(static_cast <T*> (this)->*next) ()) {
*data_ = buffer;
*size_ = pos;
return;
}
if (!(static_cast <T*> (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: