mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
factoring to support debugging of Dict iterators - no semantic changes
This commit is contained in:
parent
b4a44ed663
commit
9f68002392
2 changed files with 18 additions and 15 deletions
30
src/Dict.cc
30
src/Dict.cc
|
@ -1527,7 +1527,7 @@ void Dictionary::MakeRobustCookie(IterCookie* cookie)
|
|||
|
||||
IterCookie* Dictionary::InitForIterationNonConst() //const
|
||||
{
|
||||
num_iterators++;
|
||||
IncrIters();
|
||||
return new IterCookie(const_cast<Dictionary*>(this));
|
||||
}
|
||||
|
||||
|
@ -1535,7 +1535,7 @@ void Dictionary::StopIterationNonConst(IterCookie* cookie) //const
|
|||
{
|
||||
ASSERT(num_iterators > 0);
|
||||
if ( num_iterators > 0 )
|
||||
num_iterators--;
|
||||
DecrIters();
|
||||
delete cookie;
|
||||
}
|
||||
|
||||
|
@ -1549,7 +1549,7 @@ void* Dictionary::NextEntryNonConst(detail::HashKey*& h, IterCookie*& c, bool re
|
|||
if ( ! table )
|
||||
{
|
||||
if ( num_iterators > 0 )
|
||||
num_iterators--;
|
||||
DecrIters();
|
||||
delete c;
|
||||
c = nullptr;
|
||||
return nullptr; //end of iteration.
|
||||
|
@ -1589,7 +1589,7 @@ void* Dictionary::NextEntryNonConst(detail::HashKey*& h, IterCookie*& c, bool re
|
|||
if ( c->next >= capacity )
|
||||
{//end.
|
||||
if ( num_iterators > 0 )
|
||||
num_iterators--;
|
||||
DecrIters();
|
||||
delete c;
|
||||
c = nullptr;
|
||||
return nullptr; //end of iteration.
|
||||
|
@ -1641,7 +1641,7 @@ DictIterator::DictIterator(const Dictionary* d, detail::DictEntry* begin, detail
|
|||
// violate the constness guarantees of const-begin()/end() and cbegin()/cend(), but we're not modifying the
|
||||
// actual data in the collection, just a counter in the wrapper of the collection.
|
||||
dict = const_cast<Dictionary*>(d);
|
||||
dict->num_iterators++;
|
||||
dict->IncrIters();
|
||||
}
|
||||
|
||||
DictIterator::~DictIterator()
|
||||
|
@ -1649,7 +1649,7 @@ DictIterator::~DictIterator()
|
|||
if ( dict )
|
||||
{
|
||||
assert(dict->num_iterators > 0);
|
||||
dict->num_iterators--;
|
||||
dict->DecrIters();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1673,13 +1673,13 @@ DictIterator::DictIterator(const DictIterator& that)
|
|||
if ( dict )
|
||||
{
|
||||
assert(dict->num_iterators > 0);
|
||||
dict->num_iterators--;
|
||||
dict->DecrIters();
|
||||
}
|
||||
|
||||
dict = that.dict;
|
||||
curr = that.curr;
|
||||
end = that.end;
|
||||
dict->num_iterators++;
|
||||
dict->IncrIters();
|
||||
}
|
||||
|
||||
DictIterator& DictIterator::operator=(const DictIterator& that)
|
||||
|
@ -1690,13 +1690,13 @@ DictIterator& DictIterator::operator=(const DictIterator& that)
|
|||
if ( dict )
|
||||
{
|
||||
assert(dict->num_iterators > 0);
|
||||
dict->num_iterators--;
|
||||
dict->DecrIters();
|
||||
}
|
||||
|
||||
dict = that.dict;
|
||||
curr = that.curr;
|
||||
end = that.end;
|
||||
dict->num_iterators++;
|
||||
dict->IncrIters();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -1709,7 +1709,7 @@ DictIterator::DictIterator(DictIterator&& that)
|
|||
if ( dict )
|
||||
{
|
||||
assert(dict->num_iterators > 0);
|
||||
dict->num_iterators--;
|
||||
dict->DecrIters();
|
||||
}
|
||||
|
||||
dict = that.dict;
|
||||
|
@ -1727,7 +1727,7 @@ DictIterator& DictIterator::operator=(DictIterator&& that)
|
|||
if ( dict )
|
||||
{
|
||||
assert(dict->num_iterators > 0);
|
||||
dict->num_iterators--;
|
||||
dict->DecrIters();
|
||||
}
|
||||
|
||||
dict = that.dict;
|
||||
|
@ -1809,7 +1809,7 @@ RobustDictIterator::RobustDictIterator(Dictionary* d) : curr(nullptr), dict(d)
|
|||
inserted = new std::vector<detail::DictEntry>();
|
||||
visited = new std::vector<detail::DictEntry>();
|
||||
|
||||
dict->num_iterators++;
|
||||
dict->IncrIters();
|
||||
dict->iterators->push_back(this);
|
||||
|
||||
// Advance the iterator one step so that we're at the first element.
|
||||
|
@ -1833,7 +1833,7 @@ RobustDictIterator::RobustDictIterator(const RobustDictIterator& other) : curr(n
|
|||
std::copy(other.visited->begin(), other.visited->end(), std::back_inserter(*visited));
|
||||
|
||||
dict = other.dict;
|
||||
dict->num_iterators++;
|
||||
dict->IncrIters();
|
||||
dict->iterators->push_back(this);
|
||||
|
||||
curr = other.curr;
|
||||
|
@ -1870,7 +1870,7 @@ void RobustDictIterator::Complete()
|
|||
if ( dict )
|
||||
{
|
||||
assert(dict->num_iterators > 0);
|
||||
dict->num_iterators--;
|
||||
dict->DecrIters();
|
||||
|
||||
dict->iterators->erase(std::remove(dict->iterators->begin(), dict->iterators->end(), this),
|
||||
dict->iterators->end());
|
||||
|
|
|
@ -477,6 +477,9 @@ private:
|
|||
RobustDictIterator MakeRobustIterator();
|
||||
detail::DictEntry GetNextRobustIteration(RobustDictIterator* iter);
|
||||
|
||||
void IncrIters() { ++num_iterators; }
|
||||
void DecrIters() { --num_iterators; }
|
||||
|
||||
//alligned on 8-bytes with 4-leading bytes. 7*8=56 bytes a dictionary.
|
||||
|
||||
// when sizeup but the current mapping is in progress. the current mapping will be ignored
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue