gopher: Use a BStackOrHeapArray as temporary buffer

And move it out of the loop, no need to construct it at
each iteration anyway.
This commit is contained in:
François Revol 2014-07-28 19:04:13 +02:00
parent 579f95647d
commit 111d695ac0

View File

@ -19,6 +19,7 @@
#include <NodeInfo.h> #include <NodeInfo.h>
#include <Path.h> #include <Path.h>
#include <Socket.h> #include <Socket.h>
#include <StackOrHeapArray.h>
#include <String.h> #include <String.h>
#include <StringList.h> #include <StringList.h>
@ -266,11 +267,11 @@ BGopherRequest::_ProtocolLoop()
//ssize_t bytesReceived = 0; //ssize_t bytesReceived = 0;
//ssize_t bytesTotal = 0; //ssize_t bytesTotal = 0;
bool dataValidated = false; bool dataValidated = false;
BStackOrHeapArray<char, 4096> chunk(kGopherBufferSize);
while (!fQuit && !receiveEnd) { while (!fQuit && !receiveEnd) {
fSocket->WaitForReadable(); fSocket->WaitForReadable();
BNetBuffer chunk(kGopherBufferSize); bytesRead = fSocket->Read(chunk, kGopherBufferSize);
bytesRead = fSocket->Read(chunk.Data(), kGopherBufferSize);
if (bytesRead < 0) { if (bytesRead < 0) {
readError = bytesRead; readError = bytesRead;
@ -278,7 +279,7 @@ BGopherRequest::_ProtocolLoop()
} else if (bytesRead == 0) } else if (bytesRead == 0)
receiveEnd = true; receiveEnd = true;
fInputBuffer.AppendData(chunk.Data(), bytesRead); fInputBuffer.AppendData(chunk, bytesRead);
if (!dataValidated) { if (!dataValidated) {
size_t i; size_t i;