Skip to content

Commit 6d1a9a6

Browse files
authored
Refactoring rfunNames for copile time definition (in data.table.h)
1 parent 1a167e4 commit 6d1a9a6

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

src/froll.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "data.table.h"
22

3+
const char *const rfunNames[] = {
4+
"MEAN", "SUM", "MAX", "MIN", "PROD", "MEDIAN", "VAR", "SD"}; //constant definition of froll functions
35
/*
46
OpenMP is used here to parallelize the loops in most of the
57
implementations of rolling functions.
@@ -21,16 +23,8 @@
2123
*/
2224
void frollfun(rollfun_t rfun, unsigned int algo, const double *x, uint64_t nx, ans_t *ans, int k, int align, double fill, bool narm, int hasnf, bool verbose, bool par) {
2325
double tic = 0;
24-
char rfunStr[7];
25-
26-
const char *rfunNames[] = {
27-
"MEAN", "SUM", "MAX", "MIN", "PROD", "MEDIAN", "VAR", "SD"};
28-
29-
if (verbose){
26+
if (verbose)
3027
tic = omp_get_wtime();
31-
snprintf(rfunStr, sizeof(rfunStr), "%s", rfunNames[rfun]);
32-
}
33-
3428
if (nx < k) { // if window width bigger than input just return vector of fill values
3529
if (verbose)
3630
snprintf(end(ans->message[0]), 500, _("%s: window width longer than input vector, returning all NA vector\n"), __func__);
@@ -112,7 +106,7 @@ void frollfun(rollfun_t rfun, unsigned int algo, const double *x, uint64_t nx, a
112106
}
113107
}
114108
if (verbose) {
115-
snprintf(end(ans->message[0]), 500, _("%s: processing fun %s algo %s took %.3fs\n"), __func__, rfunStr, (algo == 0) ? "fast" : "exact", omp_get_wtime()-tic);
109+
snprintf(end(ans->message[0]), 500, _("%s: processing fun %s algo %s took %.3fs\n"), __func__, rfunNames[rfun], (algo == 0) ? "fast" : "exact", omp_get_wtime()-tic);
116110
}
117111
}
118112

0 commit comments

Comments
 (0)