]> git.lyx.org Git - features.git/commitdiff
Small optimization for the unicodesymbols patch
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 28 Jan 2007 10:07:17 +0000 (10:07 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 28 Jan 2007 10:07:17 +0000 (10:07 +0000)
* 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

src/encoding.C

index d8a175b992e12d8fb1e43d24dae29b37b716ef30..d8e70377b005913459de23d876b366d0211e15ee 100644 (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;
 }