TexRow::getRowFromIdPos(): Don't assume a vector container and really tiny optimization (don't access the same item multiple time).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26949 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-10-18 16:07:04 +00:00
parent 30a777e8a8
commit 2b65ee6030

View File

@ -61,22 +61,24 @@ bool TexRow::getIdFromRow(int row, int & id, int & pos) const
int TexRow::getRowFromIdPos(int id, int pos) const
{
int bestrow = 0;
bool foundid = false;
// this loop finds the last *nonempty* row whith the same id
// this loop finds the last *nonempty* row with the same id
// and position <= pos
for (unsigned r = 0, n = rowlist.size(); r != n; ++r) {
if (rowlist[r].id() == id && rowlist[r].pos() <= pos) {
RowList::const_iterator bestrow = rowlist.begin();
RowList::const_iterator it = rowlist.begin();
RowList::const_iterator const end = rowlist.end();
for (; it != end; ++it) {
if (it->id() == id && it->pos() <= pos) {
foundid = true;
if (rowlist[bestrow].id() != id || rowlist[r].pos() > rowlist[bestrow].pos())
bestrow = r;
if (bestrow->id() != id || it->pos() > bestrow->pos())
bestrow = it;
} else if (foundid)
break;
}
if (!foundid)
return rowlist.size();
return bestrow;
return distance(rowlist.begin(), bestrow);
}