From bcfc98e111aeefd6406523f07df762163f0e1524 Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 13 Jul 2010 23:54:37 +0000 Subject: Don't reference rows before they're put on the stack --- project2/variables.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/project2/variables.cpp b/project2/variables.cpp index cafb336..9aa1a5b 100644 --- a/project2/variables.cpp +++ b/project2/variables.cpp @@ -63,23 +63,25 @@ class VariableUri : public VariableImplDyn { class VariableParent : public VariableImplDyn, public RowUser { public: - VariableParent(const Glib::ustring & src, RowUser * dep) : - VariableImplDyn(Glib::ustring(std::find_if(src.begin(), src.end(), isalpha), src.end())) + VariableParent(const Glib::ustring & src, const RowUser * d) : + VariableImplDyn(Glib::ustring(std::find_if(src.begin(), src.end(), isalpha), src.end())), + row(NULL), + depth(src.length() - source.length()), + dep(d) { - PerRowValues::RowValuesStack::const_iterator r = PerRowValues::Stack().end(); - size_t p = src.length() - source.length(); - while (--p) { - r--; - } - row = *r; - row->use(this); - if (dep) { - row->use(dep); - } } const Glib::ustring & value() const { if (!cacheValid) { + if (!row) { + PerRowValues::RowValuesStack::const_reverse_iterator r = PerRowValues::Stack().rbegin(); + for (size_t p = depth; --p; r++) ; + row = *r; + row->use(this); + if (dep) { + row->use(dep); + } + } cache = row->getCurrentValue(source); cacheValid = true; } @@ -90,7 +92,9 @@ class VariableParent : public VariableImplDyn, public RowUser { cacheValid = false; } protected: - const PerRowValues * row; + mutable const PerRowValues * row; + const size_t depth; + const RowUser * dep; }; class VariableParse : public VariableImplDyn, public RowUser { -- cgit v1.2.3