Skip to content

Commit c9d5cd7

Browse files
committed
Merge branch 'master' into froll-n0
2 parents 4672c23 + 4f6a365 commit c9d5cd7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/uniqlist.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,16 @@ SEXP uniqlengths(SEXP x, SEXP n) {
150150
// seems very similar to rbindlist.c:uniq_lengths. TODO: centralize into common function
151151
if (TYPEOF(x) != INTSXP) error(_("Input argument 'x' to 'uniqlengths' must be an integer vector"));
152152
if (TYPEOF(n) != INTSXP || length(n) != 1) error(_("Input argument 'n' to 'uniqlengths' must be an integer vector of length 1"));
153-
R_len_t len = length(x);
153+
const R_len_t len = length(x);
154154
SEXP ans = PROTECT(allocVector(INTSXP, len));
155+
156+
const int *px = INTEGER_RO(x);
157+
int *pans = INTEGER(ans);
158+
155159
for (R_len_t i=1; i<len; i++) {
156-
INTEGER(ans)[i-1] = INTEGER(x)[i] - INTEGER(x)[i-1];
160+
pans[i-1] = px[i] - px[i-1];
157161
}
158-
if (len>0) INTEGER(ans)[len-1] = INTEGER(n)[0] - INTEGER(x)[len-1] + 1;
162+
if (len>0) pans[len-1] = INTEGER(n)[0] - px[len-1] + 1;
159163
UNPROTECT(1);
160164
return(ans);
161165
}

src/utils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ bool within_int32_repres(double x) {
44
// N.B. (int)2147483647.99 is not undefined behaviour since s 6.3.1.4 of the C
55
// standard states that behaviour is undefined only if the integral part of a
66
// finite value of standard floating type cannot be represented.
7+
// Also, note that these are not the same values you would get from INT32_MAX and INT32_MIN
78
return R_FINITE(x) && x < 2147483648 && x > -2147483648;
89
}
910

0 commit comments

Comments
 (0)