ConstPointer duplicate_poly_if_needed(const std::uint64_t *poly, int coeff_count, int coeff_uint64_count, int new_coeff_count, int new_coeff_uint64_count, bool force, MemoryPool &pool) { #ifdef _DEBUG if (poly == nullptr && coeff_count > 0 && coeff_uint64_count > 0) { throw invalid_argument("poly"); } if (coeff_count < 0) { throw invalid_argument("coeff_count"); } if (coeff_uint64_count < 0) { throw invalid_argument("coeff_uint64_count"); } if (new_coeff_count < 0) { throw invalid_argument("new_coeff_count"); } if (new_coeff_uint64_count < 0) { throw invalid_argument("new_coeff_uint64_count"); } #endif if (!force && coeff_count >= new_coeff_count && coeff_uint64_count == new_coeff_uint64_count) { return ConstPointer::Aliasing(poly); } Pointer allocation = pool.get_for_uint64_count(new_coeff_count * new_coeff_uint64_count); set_poly_poly(poly, coeff_count, coeff_uint64_count, new_coeff_count, new_coeff_uint64_count, allocation.get()); ConstPointer const_allocation; const_allocation.acquire(allocation); return const_allocation; }
ConstPointer duplicate_uint_if_needed(const std::uint64_t *uint, int uint64_count, int new_uint64_count, bool force, MemoryPool &pool) { #ifdef _DEBUG if (uint == nullptr && uint64_count > 0) { throw invalid_argument("uint"); } if (uint64_count < 0) { throw invalid_argument("uint64_count"); } if (new_uint64_count < 0) { throw invalid_argument("new_uint64_count"); } #endif if (!force && uint64_count >= new_uint64_count) { return ConstPointer::Aliasing(uint); } Pointer allocation = pool.get_for_uint64_count(new_uint64_count); set_uint_uint(uint, uint64_count, new_uint64_count, allocation.get()); ConstPointer const_allocation; const_allocation.acquire(allocation); return const_allocation; }
Pointer duplicate_if_needed(uint64_t *original, int uint64_count, bool condition, MemoryPool &pool) { #ifdef _DEBUG if (original == nullptr && uint64_count > 0) { throw invalid_argument("original"); } if (uint64_count < 0) { throw invalid_argument("uint64_count"); } #endif if (condition == false) { return Pointer::Aliasing(original); } Pointer allocation = pool.get_for_uint64_count(uint64_count); memcpy(allocation.get(), original, uint64_count * bytes_per_uint64); return allocation; }