Minor optimization in _encode_array