Skip to content

Commit

Permalink
Reduce use of mod operator for recycling to improve performance; from
Browse files Browse the repository at this point in the history
Tomas Kalibara. Addresses a performance degredation introduced in
rbind/cbind when long vector support was added.


git-svn-id: https://svn.r-project.org/R/trunk@68663 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
luke committed Jul 15, 2015
1 parent c2ac2b1 commit bf34886
Show file tree
Hide file tree
Showing 13 changed files with 515 additions and 444 deletions.
34 changes: 29 additions & 5 deletions src/include/R_ext/Itermacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,27 @@
LOOP_WITH_INTERRUPT_CHECK(R_ITERATE_CORE, ncheck, n, i, loop_body); \
} while (0)

#define MOD_ITERATE_CORE(n, n1, n2, i, i1, i2, loop_body) do { \

#define MOD_ITERATE1_CORE(n, n1, i, i1, loop_body) do { \
for (; i < n; \
i1 = (++i1 == n1) ? 0 : i1, \
++i) { \
loop_body \
} \
} while (0)

#define MOD_ITERATE1(n, n1, i, i1, loop_body) do { \
i = i1 = 0; \
MOD_ITERATE1_CORE(n, n1, i, i1, loop_body); \
} while (0)

#define MOD_ITERATE1_CHECK(ncheck, n, n1, i, i1, loop_body) do { \
i = i1 = 0; \
LOOP_WITH_INTERRUPT_CHECK(MOD_ITERATE1_CORE, ncheck, n, \
n1, i, i1, loop_body); \
} while (0)

#define MOD_ITERATE2_CORE(n, n1, n2, i, i1, i2, loop_body) do { \
for (; i < n; \
i1 = (++i1 == n1) ? 0 : i1, \
i2 = (++i2 == n2) ? 0 : i2, \
Expand All @@ -60,17 +80,21 @@
} \
} while (0)

#define MOD_ITERATE(n, n1, n2, i, i1, i2, loop_body) do { \
#define MOD_ITERATE2(n, n1, n2, i, i1, i2, loop_body) do { \
i = i1 = i2 = 0; \
MOD_ITERATE_CORE(n, n1, n2, i, i1, i2, loop_body); \
MOD_ITERATE2_CORE(n, n1, n2, i, i1, i2, loop_body); \
} while (0)

#define MOD_ITERATE_CHECK(ncheck, n, n1, n2, i, i1, i2, loop_body) do { \
#define MOD_ITERATE2_CHECK(ncheck, n, n1, n2, i, i1, i2, loop_body) do { \
i = i1 = i2 = 0; \
LOOP_WITH_INTERRUPT_CHECK(MOD_ITERATE_CORE, ncheck, n, \
LOOP_WITH_INTERRUPT_CHECK(MOD_ITERATE2_CORE, ncheck, n, \
n1, n2, i, i1, i2, loop_body); \
} while (0)

#define MOD_ITERATE MOD_ITERATE2
#define MOD_ITERATE_CORE MOD_ITERATE2_CORE
#define MOD_ITERATE_CHECK MOD_ITERATE2_CHECK

#define MOD_ITERATE3_CORE(n, n1, n2, n3, i, i1, i2, i3, loop_body) do { \
for (; i < n; \
i1 = (++i1 == n1) ? 0 : i1, \
Expand Down
Loading

0 comments on commit bf34886

Please sign in to comment.