Small optimization for the unicodesymbols patch

* src/encoding.C
	(LaTeXNamesEqual): Delete comparison class: It is no longer needed
	(Encodings::getFromLaTeXName): Don't use std::find_if since it makes
	copies of the map contents


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16903 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2007-01-28 10:07:17 +00:00
parent ba7c5463cb
commit fdba3fadfe

View File

@ -236,32 +236,18 @@ Encoding const * Encodings::getFromLyXName(string const & name) const
}
namespace {
class LaTeXNamesEqual : public std::unary_function<std::pair<std::string, Encoding>, bool> {
public:
LaTeXNamesEqual(string const & LaTeXName)
: LaTeXName_(LaTeXName) {}
bool operator()(std::pair<std::string, Encoding> const & encoding) const
{
return encoding.second.latexName() == LaTeXName_;
}
private:
string LaTeXName_;
};
} // namespace anon
Encoding const * Encodings::getFromLaTeXName(string const & name) const
{
EncodingList::const_iterator const it =
std::find_if(encodinglist.begin(), encodinglist.end(),
LaTeXNamesEqual(name));
if (it != encodinglist.end())
return &it->second;
else
return 0;
// We don't use std::find_if because it makes copies of the pairs in
// the map.
// This linear search is OK since we don't have many encodings.
// Users could even optimize it by putting the encodings they use
// most at the top of lib/encodings.
EncodingList::const_iterator const end = encodinglist.end();
for (EncodingList::const_iterator it = encodinglist.begin(); it != end; ++it)
if (it->second.latexName() == name)
return &it->second;
return 0;
}