[llvm-commits] implement and use SmallVector::data()
Jay Foad
jay.foad at gmail.com
Wed May 20 03:34:07 PDT 2009
SmallVector::operator[] has this comment:
/* These asserts could be "Begin + idx < End", but there are lots of places
in llvm where we use &v[v.size()] instead of v.end(). */
reference operator[](unsigned idx) {
assert (Begin + idx <= End);
return Begin[idx];
}
const_reference operator[](unsigned idx) const {
assert (Begin + idx <= End);
return Begin[idx];
}
I think this is a bit ugly, and rather non-standard, because it means
SmallVector behaves differently from std::vector.
The attached patch adds a data() method to SmallVector, following DR 464:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#464
... and tightens up the asserts in operator[], and converts code like
"foo(&vec[0], vec.size())" to "foo(vec.data(), vec.size())" when it
was triggering the assert. It passes "make check" and cfe's "make
test", and llvm-gcc still bootstraps.
Thoughts?
Thanks,
Jay.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.data
Type: application/octet-stream
Size: 46398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090520/edf377dd/attachment.obj>
More information about the llvm-commits
mailing list