perfs: avoid using int div (%) for wrapping buffers
This commit is contained in:
parent
9cefcb7283
commit
882077b044
@ -339,7 +339,9 @@ static bool skipUntilBoundary(const string &delimiter,
|
|||||||
if (!delimiterqueue)
|
if (!delimiterqueue)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
delimiterqueue[delimiterpos++ % endpos] = c;
|
delimiterqueue[delimiterpos++] = c;
|
||||||
|
if (delimiterpos == endpos)
|
||||||
|
delimiterpos = 0;
|
||||||
|
|
||||||
if (compareStringToQueue(delimiterStr, delimiterqueue,
|
if (compareStringToQueue(delimiterStr, delimiterqueue,
|
||||||
delimiterpos, endpos)) {
|
delimiterpos, endpos)) {
|
||||||
@ -535,7 +537,6 @@ static void parseSinglePart(const string &toboundary,
|
|||||||
boundaryqueue = new char[endpos];
|
boundaryqueue = new char[endpos];
|
||||||
memset(boundaryqueue, 0, endpos);
|
memset(boundaryqueue, 0, endpos);
|
||||||
}
|
}
|
||||||
int boundarypos = 0;
|
|
||||||
|
|
||||||
*boundarysize = 0;
|
*boundarysize = 0;
|
||||||
|
|
||||||
@ -543,6 +544,7 @@ static void parseSinglePart(const string &toboundary,
|
|||||||
string line;
|
string line;
|
||||||
bool toboundaryIsEmpty = (toboundary == "");
|
bool toboundaryIsEmpty = (toboundary == "");
|
||||||
char c;
|
char c;
|
||||||
|
int boundarypos = 0;
|
||||||
while (mimeSource->getChar(&c)) {
|
while (mimeSource->getChar(&c)) {
|
||||||
if (c == '\n') { ++*nbodylines; ++*nlines; }
|
if (c == '\n') { ++*nbodylines; ++*nlines; }
|
||||||
|
|
||||||
@ -550,7 +552,9 @@ static void parseSinglePart(const string &toboundary,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// find boundary
|
// find boundary
|
||||||
boundaryqueue[boundarypos++ % endpos] = c;
|
boundaryqueue[boundarypos++] = c;
|
||||||
|
if (boundarypos == endpos)
|
||||||
|
boundarypos = 0;
|
||||||
|
|
||||||
if (compareStringToQueue(_toboundaryStr, boundaryqueue,
|
if (compareStringToQueue(_toboundaryStr, boundaryqueue,
|
||||||
boundarypos, endpos)) {
|
boundarypos, endpos)) {
|
||||||
|
|||||||
@ -93,7 +93,7 @@ void Binc::MimePart::getBody(string &s,
|
|||||||
{
|
{
|
||||||
mimeSource->reset();
|
mimeSource->reset();
|
||||||
mimeSource->seek(bodystartoffsetcrlf + startoffset);
|
mimeSource->seek(bodystartoffsetcrlf + startoffset);
|
||||||
|
s.reserve(length);
|
||||||
if (startoffset + length > bodylength)
|
if (startoffset + length > bodylength)
|
||||||
length = bodylength - startoffset;
|
length = bodylength - startoffset;
|
||||||
|
|
||||||
|
|||||||
@ -42,9 +42,12 @@ using namespace ::std;
|
|||||||
inline bool compareStringToQueue(const char *s_in, char *bqueue,
|
inline bool compareStringToQueue(const char *s_in, char *bqueue,
|
||||||
int pos, int size)
|
int pos, int size)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i) {
|
||||||
if (s_in[i] != bqueue[(pos + i) % size])
|
if (s_in[i] != bqueue[pos])
|
||||||
return false;
|
return false;
|
||||||
|
if (++pos == size)
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user