fix pull #3620
add some array bounds check optimizations