From bef58b3b16d3b3c4a13c2c2070cfe1598c1e4b03 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 16 Jul 2008 12:09:54 +0000 Subject: [PATCH] Optimisation: away creation of FontTable for each FontList::fontIterator() call. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25664 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/FontList.cpp | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/FontList.cpp b/src/FontList.cpp index f6b456d9db..954ab4a1d5 100644 --- a/src/FontList.cpp +++ b/src/FontList.cpp @@ -28,34 +28,28 @@ using namespace std; namespace lyx { -namespace { - -class matchFT -{ -public: - /// used by lower_bound and upper_bound - int operator()(FontTable const & a, FontTable const & b) const { - return a.pos() < b.pos(); - } -}; - -} // anon namespace FontList::iterator FontList::fontIterator(pos_type pos) { - static Font dummy; - FontTable search_elem(pos, dummy); - return lower_bound(list_.begin(), list_.end(), search_elem, - matchFT()); + FontList::iterator it = list_.begin(); + FontList::iterator end = list_.end(); + for (; it != end; ++it) { + if (it->pos() >= pos) + break; + } + return it; } FontList::const_iterator FontList::fontIterator(pos_type pos) const { - static Font dummy; - FontTable search_elem(pos, dummy); - return lower_bound(list_.begin(), list_.end(), search_elem, - matchFT()); + FontList::const_iterator it = list_.begin(); + FontList::const_iterator end = list_.end(); + for (; it != end; ++it) { + if (it->pos() >= pos) + break; + } + return it; } -- 2.39.2