Some cleanup of growable arrays:
* moved declarations closer to where they are used
* assertions
* documentation
* added const where possible
* some early returns to avoid doing unecessary work

--HG--
extra : histedit_source : e8ef2f6d7f7b372242b3b1d43ec53eb0c88b69b2%2C366748989d0ecb03541d05d974e4e974a7f16ecb