From 882077b0440e038b9800e22854c04ec173cf4952 Mon Sep 17 00:00:00 2001 From: "\"Jean-Francois Dockes ext:(%22)" Date: Sun, 21 Aug 2011 10:11:19 +0200 Subject: [PATCH] perfs: avoid using int div (%) for wrapping buffers --- src/bincimapmime/mime-parsefull.cc | 12 ++++++++---- src/bincimapmime/mime-printbody.cc | 2 +- src/bincimapmime/mime-utils.h | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/bincimapmime/mime-parsefull.cc b/src/bincimapmime/mime-parsefull.cc index 43e91e26..050cf498 100644 --- a/src/bincimapmime/mime-parsefull.cc +++ b/src/bincimapmime/mime-parsefull.cc @@ -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)) { diff --git a/src/bincimapmime/mime-printbody.cc b/src/bincimapmime/mime-printbody.cc index 66472bba..d46acb0b 100644 --- a/src/bincimapmime/mime-printbody.cc +++ b/src/bincimapmime/mime-printbody.cc @@ -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; diff --git a/src/bincimapmime/mime-utils.h b/src/bincimapmime/mime-utils.h index eec6bb09..19b10b63 100644 --- a/src/bincimapmime/mime-utils.h +++ b/src/bincimapmime/mime-utils.h @@ -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; }