perfs: avoid using int div (%) for wrapping buffers

This commit is contained in:
"Jean-Francois Dockes ext:(%22)
2011-08-21 10:11:19 +02:00
parent 9cefcb7283
commit 882077b044
3 changed files with 14 additions and 7 deletions
+8 -4
View File
@@ -339,8 +339,10 @@ static bool skipUntilBoundary(const string &delimiter,
if (!delimiterqueue)
continue;
delimiterqueue[delimiterpos++ % endpos] = c;
delimiterqueue[delimiterpos++] = c;
if (delimiterpos == endpos)
delimiterpos = 0;
if (compareStringToQueue(delimiterStr, delimiterqueue,
delimiterpos, endpos)) {
foundBoundary = true;
@@ -535,7 +537,6 @@ static void parseSinglePart(const string &toboundary,
boundaryqueue = new char[endpos];
memset(boundaryqueue, 0, endpos);
}
int boundarypos = 0;
*boundarysize = 0;
@@ -543,6 +544,7 @@ static void parseSinglePart(const string &toboundary,
string line;
bool toboundaryIsEmpty = (toboundary == "");
char c;
int boundarypos = 0;
while (mimeSource->getChar(&c)) {
if (c == '\n') { ++*nbodylines; ++*nlines; }
@@ -550,7 +552,9 @@ static void parseSinglePart(const string &toboundary,
continue;
// find boundary
boundaryqueue[boundarypos++ % endpos] = c;
boundaryqueue[boundarypos++] = c;
if (boundarypos == endpos)
boundarypos = 0;
if (compareStringToQueue(_toboundaryStr, boundaryqueue,
boundarypos, endpos)) {
+1 -1
View File
@@ -93,7 +93,7 @@ void Binc::MimePart::getBody(string &s,
{
mimeSource->reset();
mimeSource->seek(bodystartoffsetcrlf + startoffset);
s.reserve(length);
if (startoffset + length > bodylength)
length = bodylength - startoffset;
+5 -2
View File
@@ -42,9 +42,12 @@ using namespace ::std;
inline bool compareStringToQueue(const char *s_in, char *bqueue,
int pos, int size)
{
for (int i = 0; i < size; ++i)
if (s_in[i] != bqueue[(pos + i) % size])
for (int i = 0; i < size; ++i) {
if (s_in[i] != bqueue[pos])
return false;
if (++pos == size)
pos = 0;
}
return true;
}