issue #3812: performance improvement, 1. add vector reserve 2. use C++11 range loop