forked from OSchip/llvm-project
add a blurb on const versions of chain traversals and a word of caution
llvm-svn: 99638
This commit is contained in:
parent
6096d5a279
commit
6d6cf8ff00
|
@ -1211,14 +1211,14 @@ and erasing, but does not support iteration.</p>
|
||||||
|
|
||||||
<div class="doc_text">
|
<div class="doc_text">
|
||||||
|
|
||||||
<p>SmallPtrSet has all the advantages of SmallSet (and a SmallSet of pointers is
|
<p>SmallPtrSet has all the advantages of <tt>SmallSet</tt> (and a <tt>SmallSet</tt> of pointers is
|
||||||
transparently implemented with a SmallPtrSet), but also supports iterators. If
|
transparently implemented with a <tt>SmallPtrSet</tt>), but also supports iterators. If
|
||||||
more than 'N' insertions are performed, a single quadratically
|
more than 'N' insertions are performed, a single quadratically
|
||||||
probed hash table is allocated and grows as needed, providing extremely
|
probed hash table is allocated and grows as needed, providing extremely
|
||||||
efficient access (constant time insertion/deleting/queries with low constant
|
efficient access (constant time insertion/deleting/queries with low constant
|
||||||
factors) and is very stingy with malloc traffic.</p>
|
factors) and is very stingy with malloc traffic.</p>
|
||||||
|
|
||||||
<p>Note that, unlike std::set, the iterators of SmallPtrSet are invalidated
|
<p>Note that, unlike <tt>std::set</tt>, the iterators of <tt>SmallPtrSet</tt> are invalidated
|
||||||
whenever an insertion occurs. Also, the values visited by the iterators are not
|
whenever an insertion occurs. Also, the values visited by the iterators are not
|
||||||
visited in sorted order.</p>
|
visited in sorted order.</p>
|
||||||
|
|
||||||
|
@ -1960,6 +1960,10 @@ for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i
|
||||||
errs() << *Inst << "\n";
|
errs() << *Inst << "\n";
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
Note that dereferencing a <tt>Value::use_iterator</tt is not a very cheap
|
||||||
|
operation. Instead of performing <tt>*i</tt> above several times, consider
|
||||||
|
doing it only once in the loop body and reusing its result.
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>Alternatively, it's common to have an instance of the <a
|
<p>Alternatively, it's common to have an instance of the <a
|
||||||
|
@ -1981,11 +1985,13 @@ for (User::op_iterator i = pi->op_begin(), e = pi->op_end(); i != e; ++i)
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--
|
<p>Declaring objects as <tt>const</tt> is an important tool of enforcing
|
||||||
def-use chains ("finding all users of"): Value::use_begin/use_end
|
mutation free algorithms (such as analyses etc.). For this purpose above
|
||||||
use-def chains ("finding all values used"): User::op_begin/op_end [op=operand]
|
iterators come in constant flavors as <tt>Value::const_use_iterator</tt>
|
||||||
-->
|
and <tt>Value::const_op_iterator</tt>. They automatically arise when
|
||||||
|
calling <tt>use/op_begin()</tt> on <tt>const Value*</tt>s or
|
||||||
|
<tt>const User*</tt>s respectively. Upon dereferencing, they return
|
||||||
|
<tt>const Use*</tt>s. Otherwise the above patterns remain unchanged.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--_______________________________________________________________________-->
|
<!--_______________________________________________________________________-->
|
||||||
|
|
Loading…
Reference in New Issue