collections: add Set::retain
commit08d565d96d4d208c54ea3e01455d52759662f3bb
authorEugene Letuchy <eletuchy@fb.com>
Wed, 14 May 2014 03:56:35 +0000 (13 20:56 -0700)
committerJoelMarcey <joelm@fb.com>
Mon, 19 May 2014 16:21:49 +0000 (19 09:21 -0700)
tree8a2259cc909aa6415b04c2c933091468de8723ca
parentf368c60650669ae7fc83ecdd2b02f81230368085
collections: add Set::retain

Summary: The same as Set::filter, but instead of creating a new result Set to
 hold the values that pass the given predicate function, instead
 mutate the original set and remove values that don't pass the
 predicate.

 This is useful for code that wants to destructively update the Set without
 intermediate unnecessary allocations, since we invalidate iterators for
 `foreach ($s as $i) { ... $s->remove($i); ... }`.

Reviewed By: andrewparoski

Subscribers: jdelong, julienv, hphp-diffslists, ps, joelm

Differential Revision: D1328836
hphp/hack/hhi/Set.hhi
hphp/runtime/ext/ext_collections.cpp
hphp/runtime/ext/ext_collections.h
hphp/system/idl/collections.idl.json
hphp/test/slow/collection_classes/retain.php
hphp/test/slow/collection_classes/retain.php.expect