From 6d6cf8ff004c1ccd3600ed4207495b74612a7525 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 26 Mar 2010 19:30:47 +0000 Subject: [PATCH] add a blurb on const versions of chain traversals and a word of caution llvm-svn: 99638 --- llvm/docs/ProgrammersManual.html | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/llvm/docs/ProgrammersManual.html b/llvm/docs/ProgrammersManual.html index cf936d1571a8..b6c9a8793c21 100644 --- a/llvm/docs/ProgrammersManual.html +++ b/llvm/docs/ProgrammersManual.html @@ -1211,14 +1211,14 @@ and erasing, but does not support iteration.

-

SmallPtrSet has all the advantages of SmallSet (and a SmallSet of pointers is -transparently implemented with a SmallPtrSet), but also supports iterators. If +

SmallPtrSet has all the advantages of SmallSet (and a SmallSet of pointers is +transparently implemented with a SmallPtrSet), but also supports iterators. If more than 'N' insertions are performed, a single quadratically probed hash table is allocated and grows as needed, providing extremely efficient access (constant time insertion/deleting/queries with low constant factors) and is very stingy with malloc traffic.

-

Note that, unlike std::set, the iterators of SmallPtrSet are invalidated +

Note that, unlike std::set, the iterators of SmallPtrSet are invalidated whenever an insertion occurs. Also, the values visited by the iterators are not visited in sorted order.

@@ -1960,6 +1960,10 @@ for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i errs() << *Inst << "\n"; } +Note that dereferencing a Value::use_iterator*i above several times, consider +doing it only once in the loop body and reusing its result. +

Alternatively, it's common to have an instance of the - - +

Declaring objects as const is an important tool of enforcing +mutation free algorithms (such as analyses etc.). For this purpose above +iterators come in constant flavors as Value::const_use_iterator +and Value::const_op_iterator. They automatically arise when +calling use/op_begin() on const Value*s or +const User*s respectively. Upon dereferencing, they return +const Use*s. Otherwise the above patterns remain unchanged.