Extract method "resizeSlice" to reduce duplicate code.