[webkit-dev] We need OwnPtrHashMap

Maciej Stachowiak mjs at apple.com
Sun Aug 29 21:14:43 PDT 2010


On Aug 28, 2010, at 10:57 PM, Darin Adler wrote:

> We need Vector<OwnPtr> too. It has similar issues to HashMap with OwnPtr values, including the ones mentioned by Maciej.
> 
> For one example, look at CSSParser::m_floatingMediaQueryExpList.

Vector<OwnPtr> actually works[1], and I have an almost complete patch to fully OwnPtr-ize MediaQueryExp. The one problem is sorting - MediaQuery wants to sort the Vector<MediaQuery*> it gets with std::sort, followed by eliminating duplicates. A sort that solely uses swaps would work, but std::sort wants to make copies of the elements at times. I also tried to think of ways to cheat by copying to a vector of raw pointers and back, and it could be made to work with sufficiently aggressive use of leakPtr and adoptPtr, but at the cost of two extra copies. Yet another possibility is to use a hash to do the de-duping instead of sorting; I can't tell from context if the sorting is needed for any purpose other than subsequent de-duping.

If you can help me think of a good solution for this I'll post my patch.

Regards,
Maciej


[1] It works because:
(a) VectorTraits already takes care of all internal copies that are actually moves, by cheating and doing them with memcpy.
(b) Reads, and writes of an existing slot, all operate via a reference to the element type, so you can use -> or .get() on a returned element just fine, and you can assign in a PassOwnPtr<T> to an OwnPtr<T>&.
(c) append() and similar methods that add an element to a not-yet-existing slot all are templatized on the type of the element being added, so appending a PassOwnPtr works.

The Hash templates are more complicated, so they probably won't just work automatically.


More information about the webkit-dev mailing list