string const name = subst(lexrc.getString(),
'_', ' ');
if (hasLayout(name)) {
- LyXLayout & lay = operator[](name);
+ LyXLayout & lay =
+ const_cast<LyXLayout &>(operator[](name));
error = do_readStyle(lexrc, lay);
} else {
LyXLayout lay;
lyxerr << "Operator[] called with empty n" << endl;
string const name = (n.empty() ? defaultLayoutName() : n);
-
- LayoutList::const_iterator cit =
- find_if(layoutlist.begin(),
- layoutlist.end(),
- lyx::compare_memfun(&LyXLayout::name, name));
- if (cit == layoutlist.end()) {
- lyxerr << "We failed to find the layout '" << name
- << "' in the layout list. You MUST investigate!"
- << endl;
-
- // we require the name to exist
- lyx::Assert(false);
- }
+ static string lastLayoutName;
+ static LayoutList::difference_type lastLayoutIndex;
- return *cit;
-}
+ if (name == lastLayoutName)
+ return layoutlist[lastLayoutIndex];
-
-LyXLayout & LyXTextClass::operator[](string const & n)
-{
- lyx::Assert(!n.empty());
-
- if (n.empty())
- lyxerr << "Operator[] called with empty n" << endl;
-
- string const name = (n.empty() ? defaultLayoutName() : n);
- LayoutList::iterator it =
+ LayoutList::const_iterator cit =
find_if(layoutlist.begin(),
layoutlist.end(),
lyx::compare_memfun(&LyXLayout::name, name));
- if (it == layoutlist.end()) {
+ if (cit == layoutlist.end()) {
lyxerr << "We failed to find the layout '" << name
<< "' in the layout list. You MUST investigate!"
<< endl;
// we require the name to exist
lyx::Assert(false);
}
+
+ lastLayoutName = name;
+ lastLayoutIndex = std::distance(layoutlist.begin(), cit);
- return *it;
+ return *cit;
}
}
-LyXLayout & LyXTextClass::defaultLayout()
-{
- return operator[](defaultLayoutName());
-}
-
-
string const & LyXTextClass::name() const
{
return name_;