optimize sample_index.c