From 6078618d0de0d643fa4e44f606cf2c7b48a63c88 Mon Sep 17 00:00:00 2001 From: Ben Edgington Date: Thu, 4 Feb 2021 14:10:48 +0000 Subject: [PATCH] Add const qualifiers to arguments --- src/fft_common.c | 26 +++++++++++++------------- src/fft_common.h | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/fft_common.c b/src/fft_common.c index 5a06454..6bd7e66 100644 --- a/src/fft_common.c +++ b/src/fft_common.c @@ -16,13 +16,13 @@ #include "fft_common.h" -bool is_power_of_two(uint64_t n) { +bool is_power_of_two(const uint64_t n) { return (n & (n - 1)) == 0; } // Create an array of powers of the root of unity // The `out` array must be of size `width + 1` -C_KZG_RET expand_root_of_unity(blst_fr *roots, blst_fr *root_of_unity, uint64_t width) { +C_KZG_RET expand_root_of_unity(blst_fr *roots, const blst_fr *root_of_unity, const uint64_t width) { roots[0] = one; roots[1] = *root_of_unity; @@ -37,7 +37,7 @@ C_KZG_RET expand_root_of_unity(blst_fr *roots, blst_fr *root_of_unity, uint64_t // Create a reversed list of Fr provided // `width` is one less than the length of `roots` -C_KZG_RET reverse(blst_fr *out, blst_fr *roots, uint64_t width) { +C_KZG_RET reverse(blst_fr *out, const blst_fr *roots, const uint64_t width) { for (int i = 0; i <= width; i++) { out[i] = roots[width - i]; } @@ -45,20 +45,20 @@ C_KZG_RET reverse(blst_fr *out, blst_fr *roots, uint64_t width) { return C_KZG_SUCCESS; } -C_KZG_RET new_fft_settings(FFTSettings *s, unsigned int max_scale) { +C_KZG_RET new_fft_settings(FFTSettings *fs, const unsigned int max_scale) { C_KZG_RET ret; - s->max_width = (uint64_t)1 << max_scale; - blst_fr_from_uint64(&s->root_of_unity, scale2_root_of_unity[max_scale]); - s->expanded_roots_of_unity = malloc((s->max_width + 1) * sizeof(blst_fr)); - s->reverse_roots_of_unity = malloc((s->max_width + 1) * sizeof(blst_fr)); + fs->max_width = (uint64_t)1 << max_scale; + blst_fr_from_uint64(&fs->root_of_unity, scale2_root_of_unity[max_scale]); + fs->expanded_roots_of_unity = malloc((fs->max_width + 1) * sizeof(blst_fr)); + fs->reverse_roots_of_unity = malloc((fs->max_width + 1) * sizeof(blst_fr)); - ret = expand_root_of_unity(s->expanded_roots_of_unity, &s->root_of_unity, s->max_width); + ret = expand_root_of_unity(fs->expanded_roots_of_unity, &fs->root_of_unity, fs->max_width); if (ret != C_KZG_SUCCESS) return ret; - ret = reverse(s->reverse_roots_of_unity, s->expanded_roots_of_unity, s->max_width); + ret = reverse(fs->reverse_roots_of_unity, fs->expanded_roots_of_unity, fs->max_width); return ret; } -void free_fft_settings(FFTSettings *s) { - free(s->expanded_roots_of_unity); - free(s->reverse_roots_of_unity); +void free_fft_settings(FFTSettings *fs) { + free(fs->expanded_roots_of_unity); + free(fs->reverse_roots_of_unity); } diff --git a/src/fft_common.h b/src/fft_common.h index 59723ef..2dba473 100644 --- a/src/fft_common.h +++ b/src/fft_common.h @@ -66,8 +66,8 @@ typedef struct { blst_fr *reverse_roots_of_unity; } FFTSettings; -bool is_power_of_two(uint64_t n); -C_KZG_RET expand_root_of_unity(blst_fr * roots, blst_fr *root_of_unity, uint64_t width); -C_KZG_RET reverse(blst_fr *out, blst_fr *roots, uint64_t width); -C_KZG_RET new_fft_settings(FFTSettings *s, unsigned int max_scale); +bool is_power_of_two(const uint64_t n); +C_KZG_RET expand_root_of_unity(blst_fr * roots, const blst_fr *root_of_unity, const uint64_t width); +C_KZG_RET reverse(blst_fr *out, const blst_fr *roots, const uint64_t width); +C_KZG_RET new_fft_settings(FFTSettings *s, const unsigned int max_scale); void free_fft_settings(FFTSettings *s);