[webkit-dev] Vector iteration

Oliver Hunt oliver at apple.com
Mon Dec 1 10:07:44 PST 2014


Hi all, I just landed a patch that replaces Vector<T>::iterator and Vector<T>::const_iterator with a non-pointer object that is actually memory safe. Everything _should_ work the same as before, with a few exciting changes:

* begin() and end() can no longer be used transparently as pointers.  Happily WTF::getPtr() will do the right thing.
* The iterators them selves are larger - they have to track the current location and the source vector. It would be nice if we could avoid this within the enumeration syntax but that would require language changes.
* Iteration is bounds checked! Woo! As everyone has been switching to C++ enumeration syntax we lost all the bounds checking we were doing previously, but happily that hole is now plugged again.
* Huge and happy advantage: Vector iteration is now safe against mutation!!! Previously mutating a vector during enumeration was not memory safe, bounds safe, or in fact any kind of safe (but you weren’t doing that right?), and now it is!!!

Happily there is no performance hit from this.

—Oliver



More information about the webkit-dev mailing list