Repository: milvus-io/milvus
File: internal/core/src/storage/DiskFileManagerImpl.cpp (C++)

Code before:

    bool nullable = false;
    uint64_t total_num_rows = 0;
    if (valid_data_path.has_value()) {
        for (auto& field_data : field_datas) {
            if (field_data->IsNullable()) {
                nullable = true;
            }
            total_num_rows += field_data->get_num_rows();
        }
    }

    std::vector<uint8_t> valid_bitmap;
    if (nullable) {
        valid_bitmap.resize((total_num_rows + 7) / 8, 0);
    }

    int64_t chunk_offset = 0;
    for (auto& field_data : field_datas) {
        num_rows += uint32_t(field_data->get_valid_rows());
        if (nullable) {
            auto rows = field_data->get_num_rows();
            for (int64_t i = 0; i < rows; ++i) {
                if (field_data->is_valid(i)) {
                    auto bit_pos = chunk_offset + i;
                    valid_bitmap[bit_pos / 8] |= (1 << (bit_pos % 8));
                }
            }
            chunk_offset += rows;
        }

        cache_raw_data_to_disk_common<T>(field_data,
                                         local_chunk_manager,
                                         local_data_path,
                                         file_created,
                                         var_dim,
                                         write_offset,
                                         is_vector_array ? &offsets : nullptr);
    }

    // write num_rows and dim value to file header
    write_offset = 0;
    local_chunk_manager->Write(
        local_data_path, write_offset, &num_rows, sizeof(num_rows));
    write_offset += sizeof(num_rows);
    local_chunk_manager->Write(
        local_data_path, write_offset, &var_dim, sizeof(var_dim));

    // Write offsets file for VECTOR_ARRAY
    if (is_vector_array) {
        AssertInfo(offsets.size() == num_rows + 1,

Review comment (suggestion):
Make a inline func for this:
```
inline void set_bit(std::vector<uint8_t>& bitmap, int64_t bit_pos) {
      bitmap[bit_pos >> 3] |= (1 << (bit_pos & 0x07));
  }
```

Code after:
                                                loon_ffi_properties_,
                                                field_meta_,
                                                data_type,
                                                dim,
                                                element_type);
    } else {
        field_datas = GetFieldDatasFromStorageV2(all_remote_files,
                                                 GetFieldDataMeta().field_id,
                                                 data_type.value(),
                                                 element_type.value(),
                                                 dim,
                                                 fs_);
    }

    bool nullable = false;
    uint64_t total_num_rows = 0;
    if (valid_data_path.has_value()) {
        for (auto& field_data : field_datas) {
            if (field_data->IsNullable()) {
                nullable = true;
            }
            total_num_rows += field_data->get_num_rows();
        }
    }

    std::vector<uint8_t> valid_bitmap;
    if (nullable) {
        valid_bitmap.resize((total_num_rows + 7) / 8, 0);
    }

    int64_t chunk_offset = 0;
    for (auto& field_data : field_datas) {
        num_rows += uint32_t(field_data->get_valid_rows());
        if (nullable) {
            auto rows = field_data->get_num_rows();
            for (int64_t i = 0; i < rows; ++i) {
                if (field_data->is_valid(i)) {
                    set_bit(valid_bitmap, chunk_offset + i);
                }
            }
            chunk_offset += rows;
        }

        cache_raw_data_to_disk_common<T>(field_data,
                                         local_chunk_manager,
                                         local_data_path,
                                         file_created,
                                         var_dim,
                                         write_offset,
                                         is_vector_array ? &offsets : nullptr);
    }