- iterator beg = list_.begin();
- iterator it = beg;
- iterator endit = list_.end();
- for (; it != endit; ++it) {
- if (it->pos() >= pos)
- break;
- }
- size_t const i = distance(beg, it);
- bool notfound = (it == endit);
+ List::iterator it = fontIterator(pos);
+ bool const found = it != list_.end();
+ if (found && it->font() == font)
+ // Font is already set.
+ return;
+
+ size_t const i = distance(list_.begin(), it);
+
+ // Is position pos a beginning of a font block?
+ bool const begin = pos == 0 || !found
+ || (i > 0 && list_[i - 1].pos() == pos - 1);