SEAL icon indicating copy to clipboard operation
SEAL copied to clipboard

The reserve function can judge before allocating

Open maths644311798 opened this issue 1 year ago • 0 comments

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.

maths644311798 avatar Jun 06 '24 08:06 maths644311798