microsoft / SEAL

Microsoft SEAL is an easy-to-use and powerful homomorphic encryption library.
https://www.microsoft.com/en-us/research/group/cryptography-research/
MIT License
3.55k stars 706 forks source link

The reserve function can judge before allocating #693

Open maths644311798 opened 4 months ago

maths644311798 commented 4 months ago

In /native/src/seal/dynarray.h,

inline void reserve(std::size_t capacity)
        {
            std::size_t copy_size = std::min<>(capacity, size_);

            // Create new allocation and copy over value
            auto new_data(util::allocate<T>(capacity, pool_));
            std::copy_n(cbegin(), copy_size, new_data.get());
            std::swap(data_, new_data);

            // Set the coeff_count and capacity
            capacity_ = capacity;
            size_ = copy_size;
        }

I think we can judge if capacity > capacity_ before allocating memory. The current behavior causes the function Ciphertext::operator=(const Ciphertext &assign) slower than the construction function of Ciphertext.