etc instead of the owner/new/delete logic?
Andre'
you are right, allocation on the stack is really better here...
bernhard
That was the wrong patch... here's the correct one
bernhard
Index: src/Counters.cpp
===================================================================
--- src/Counters.cpp (revision 23138)
+++ src/Counters.cpp (working copy)
@@ -340,22 +340,47 @@
docstring Counters::theCounter(docstring const & counter)
{
+ std::set<docstring> callers;
+ return theCounter(counter, callers);
+}
+
+docstring Counters::theCounter(docstring const & counter,
+ std::set<docstring>
& callers)
+{
if (!hasCounter(counter))
return from_ascii("??");
- Counter const & c = counterList[counter];
- docstring ls = appendix() ? c.labelStringAppendix() : c.labelString();
+ docstring label;
- if (ls.empty()) {
- if (!c.master().empty())
- ls = from_ascii("\\the") + c.master() + from_ascii(".");
- ls += from_ascii("\\arabic{") + counter + "}";
+ if (callers.find(counter) == callers.end()) {
+
+ pair<std::set<docstring>::iterator, bool> result =
callers.insert(counter);
+
+ Counter const & c = counterList[counter];
+ docstring ls = appendix() ? c.labelStringAppendix() :
c.labelString();
+
+ if (ls.empty()) {
+ if (!c.master().empty())
+ ls = from_ascii("\\the") + c.master() +
from_ascii(".");
+ ls += from_ascii("\\arabic{") + counter + "}";
+ }
+
+ label = counterLabel(ls, &callers);
+
+ callers.erase(result.first);
+ } else {
+ // recursion detected
+ lyxerr << "Warning: Recursion in label for counter `"
+ << counter << "' detected"
+ << endl;
}
- return counterLabel(ls);
+
+ return label;
}
-docstring Counters::counterLabel(docstring const & format)
+docstring Counters::counterLabel(docstring const & format,
+
std::set<docstring> * callers)
{
docstring label = format;
@@ -373,10 +398,11 @@
&& lowercase(label[k]) <= 'z')
++k;
docstring counter = label.substr(j, k - j);
- docstring repl = theCounter(counter);
+ docstring repl = callers? theCounter(counter, *callers):
+ theCounter(counter);
label.replace(i, k - j + 4, repl);
}
-
+
while (true) {
//lyxerr << "label=" << to_utf8(label) << endl;
Index: src/Counters.h
===================================================================
--- src/Counters.h (revision 23138)
+++ src/Counters.h (working copy)
@@ -18,6 +18,7 @@
#include "support/docstring.h"
#include <map>
+#include <set>
namespace lyx {
@@ -105,7 +106,8 @@
docstring theCounter(docstring const & c);
/// Replace om format all the LaTeX-like macros that depend on
/// counters.
- docstring counterLabel(docstring const & format);
+ docstring counterLabel(docstring const & format,
+ std::set<docstring> * callers = 0);
/// Are we in apendix?
bool appendix() const { return appendix_; };
/// Set the state variable indicating whether we are in appendix.
@@ -115,6 +117,10 @@
/// Sets the current enclosing float.
void current_float(std::string const & f) { current_float_ = f; }
private:
+ /// returns the expanded string representation of the counter
+ /// with recursion protection through callers.
+ docstring theCounter(docstring const & c,
+ std::set<docstring> & callers);
/// Returns the value of the counter according to the
/// numbering scheme numbertype.
/* Available numbering schemes are arabic (1, 2,...), roman