avoid adding unneeded entries in confstack. fix erase-add resulting in duplicate
This commit is contained in:
parent
f8b7432280
commit
89bbfd55fe
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid [] = "@(#$Id: conftree.cpp,v 1.10 2007-08-04 07:22:43 dockes Exp $ (C) 2003 J.F.Dockes";
|
||||
static char rcsid [] = "@(#$Id: conftree.cpp,v 1.11 2007-09-27 11:02:13 dockes Exp $ (C) 2003 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -312,7 +312,11 @@ int ConfSimple::i_set(const std::string &nm, const std::string &value,
|
||||
}
|
||||
}
|
||||
}
|
||||
m_order.insert(fin, ConfLine(ConfLine::CFL_VAR, nm));
|
||||
|
||||
// It may happen that the order entry already exists because erase doesnt
|
||||
// update m_order (fix it ?)
|
||||
if (find(start, fin, ConfLine(ConfLine::CFL_VAR, nm)) == fin)
|
||||
m_order.insert(fin, ConfLine(ConfLine::CFL_VAR, nm));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -341,6 +341,28 @@ public:
|
||||
{
|
||||
if (!m_ok)
|
||||
return 0;
|
||||
|
||||
// Avoid adding unneeded entries: if the new value matches the
|
||||
// one out of the deeper config, erase or dont add it from/to
|
||||
// the topmost file
|
||||
typename list<T*>::iterator it = m_confs.begin();
|
||||
it++;
|
||||
while (it != m_confs.end()) {
|
||||
string value;
|
||||
if ((*it)->get(nm, value, sk)) {
|
||||
// This file has value for nm/sk. If it is the same as the new
|
||||
// one, no need for an entry in the topmost file. Else, stop
|
||||
// looking and add the new entry
|
||||
if (value == val) {
|
||||
m_confs.front()->erase(nm, sk);
|
||||
return true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
return m_confs.front()->set(nm, val, sk);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user