Skip to content

Commit 062554b

Browse files
committed
localize reused object cumSum + general vicinity cleanup
1 parent e2e0173 commit 062554b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/fsort.c

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

3-
#define INSERT_THRESH 200 // TODO: expose via api and test
3+
static const int INSERT_THRESH = 200; // TODO: expose via api and test
44

55
static void dinsert(double *x, const int n) { // TODO: if and when twiddled, double => ull
66
if (n<2) return;
@@ -43,13 +43,10 @@ static void dradix_r( // single-threaded recursive worker
4343
return;
4444
}
4545

46-
uint64_t cumSum=0;
47-
for (uint64_t i=0; cumSum<n; ++i) { // cumSum<n better than i<width as may return early
48-
uint64_t tmp;
49-
if ((tmp=counts[i])) { // don't cumulate through 0s, important below to save a wasteful memset to zero
50-
counts[i] = cumSum;
51-
cumSum += tmp;
52-
}
46+
for (uint64_t i = 0, cumSum = 0; cumSum < n; ++i) { // cumSum<n better than i<width as may return early
47+
if (!counts[i]) continue; // don't cumulate through 0s, important below to save a wasteful memset to zero
48+
counts[i] = cumSum;
49+
cumSum += counts[i];
5350
} // leaves cumSum==n && 0<i && i<=width
5451

5552
tmp=in;
@@ -71,10 +68,9 @@ static void dradix_r( // single-threaded recursive worker
7168
return;
7269
}
7370

74-
cumSum=0;
75-
for (int i=0; cumSum<n; ++i) { // again, cumSum<n better than i<width as it can return early
71+
for (uint64_t i = 0, cumSum = 0; cumSum < n; i++) { // again, cumSum<n better than i<width as it can return early
7672
if (counts[i] == 0) continue;
77-
uint64_t thisN = counts[i] - cumSum; // undo cummulate; i.e. diff
73+
const uint64_t thisN = counts[i] - cumSum; // undo cummulate; i.e. diff
7874
if (thisN <= INSERT_THRESH) {
7975
dinsert(in+cumSum, thisN); // for thisN==1 this'll return instantly. Probably better than several branches here.
8076
} else {

0 commit comments

Comments
 (0)