|
|
|
|
|
by lossolo
248 days ago
|
|
Quadratic pushfive is just a cautionary tale about misusing reserve_exact. Basically use reserve_exact when you know the final size (reserve once), or you're doing a one off tight sizing where memory footprint matters. Don't pre reserve inside pushfive, just push the 5 elements (Vec handles growth)
or if you know how many times you'll call pushfive in a loop, reserve up front once vec.reserve(5 * times) or use reserve instead of reserve_exact for incremental growth. |
|