Skip to content

Commit

Permalink
remove trailing whitespace (#4984)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdowle authored May 9, 2021
1 parent 357f69e commit d8e0fb3
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 54 deletions.
12 changes: 6 additions & 6 deletions R/IDateTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,20 @@ rep.ITime = function (x, ...)
class(y) = "ITime" # unlass and rep could feasibly not copy, hence use class<- not setattr()
y
}
round.ITime <- function(x, digits = c("hours", "minutes"), ...)

round.ITime <- function(x, digits = c("hours", "minutes"), ...)
{
(setattr(switch(match.arg(digits),
hours = as.integer(round(unclass(x)/3600)*3600),
minutes = as.integer(round(unclass(x)/60)*60)),
minutes = as.integer(round(unclass(x)/60)*60)),
"class", "ITime"))
}
}

trunc.ITime <- function(x, units = c("hours", "minutes"), ...)
trunc.ITime <- function(x, units = c("hours", "minutes"), ...)
{
(setattr(switch(match.arg(units),
hours = as.integer(unclass(x)%/%3600*3600),
minutes = as.integer(unclass(x)%/%60*60)),
minutes = as.integer(unclass(x)%/%60*60)),
"class", "ITime"))
}

Expand Down
2 changes: 1 addition & 1 deletion R/as.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ as.data.table.list = function(x,
eachncol = integer(n)
missing.check.names = missing(check.names)
origListNames = if (missing(.named)) names(x) else NULL # as.data.table called directly, not from inside data.table() which provides .named, #3854
empty_atomic = FALSE
empty_atomic = FALSE
for (i in seq_len(n)) {
xi = x[[i]]
if (is.null(xi)) next # eachncol already initialized to 0 by integer() above
Expand Down
4 changes: 2 additions & 2 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ replace_dot_alias = function(e) {
else if (!isTRUEorFALSE(keyby))
stop("When by and keyby are both provided, keyby must be TRUE or FALSE")
}
}
}
bynull = !missingby && is.null(by) #3530
byjoin = !is.null(by) && is.symbol(bysub) && bysub==".EACHI"
naturaljoin = FALSE
Expand Down Expand Up @@ -1347,7 +1347,7 @@ replace_dot_alias = function(e) {

if (is.data.table(jval)) {
# should set the parent class only when jval is a plain data.table #4324
if (identical(class(jval), c('data.table', 'data.frame')))
if (identical(class(jval), c('data.table', 'data.frame')))
setattr(jval, 'class', class(x)) # fix for #64
if (haskey(x) && all(key(x) %chin% names(jval)) && is.sorted(jval, by=key(x)))
setattr(jval, 'sorted', key(x))
Expand Down
2 changes: 1 addition & 1 deletion R/setops.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fintersect = function(x, y, all=FALSE) {
x = shallow(x)[, ".seqn" := rowidv(x)]
y = shallow(y)[, ".seqn" := rowidv(y)]
jn.on = c(".seqn",setdiff(names(y),".seqn"))
# fixes #4716 by preserving order of 1st (uses y[x] join) argument instead of 2nd (uses x[y] join)
# fixes #4716 by preserving order of 1st (uses y[x] join) argument instead of 2nd (uses x[y] join)
y[x, .SD, .SDcols=setdiff(names(y),".seqn"), nomatch=NULL, on=jn.on]
} else {
z = funique(x) # fixes #3034. When .. prefix in i= is implemented (TODO), this can be x[funique(..y), on=, multi=]
Expand Down
8 changes: 4 additions & 4 deletions src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,21 @@ static SEXP shallow(SEXP dt, SEXP cols, R_len_t n)
SET_OBJECT(newdt, OBJECT(dt));
IS_S4_OBJECT(dt) ? SET_S4_OBJECT(newdt) : UNSET_S4_OBJECT(newdt); // To support S4 objects that incude data.table
//SHALLOW_DUPLICATE_ATTRIB(newdt, dt); // SHALLOW_DUPLICATE_ATTRIB would be a bit neater but is only available from R 3.3.0

// TO DO: keepattr() would be faster, but can't because shallow isn't merely a shallow copy. It
// also increases truelength. Perhaps make that distinction, then, and split out, but marked
// so that the next change knows to duplicate.
// keepattr() also merely points to the entire attrbutes list and thus doesn't allow replacing
// some of its elements.

// We copy all attributes that refer to column names so that calling setnames on either
// the original or the shallow copy doesn't break anything.
SEXP index = PROTECT(getAttrib(dt, sym_index)); protecti++;
setAttrib(newdt, sym_index, shallow_duplicate(index));

SEXP sorted = PROTECT(getAttrib(dt, sym_sorted)); protecti++;
setAttrib(newdt, sym_sorted, duplicate(sorted));

SEXP names = PROTECT(getAttrib(dt, R_NamesSymbol)); protecti++;
SEXP newnames = PROTECT(allocVector(STRSXP, n)); protecti++;
if (isNull(cols)) {
Expand Down
10 changes: 5 additions & 5 deletions src/dogroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static bool anySpecialStatic(SEXP x) {
if (isNewList(x)) {
if (TRUELENGTH(x)<0)
return true; // test 2158
for (int i=0; i<n; ++i) {
for (int i=0; i<n; ++i) {
if (anySpecialStatic(VECTOR_ELT(x,i)))
return true;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
SEXP names = PROTECT(getAttrib(SDall, R_NamesSymbol)); nprotect++;
if (length(names) != length(SDall)) error(_("length(names)!=length(SD)"));
SEXP *nameSyms = (SEXP *)R_alloc(length(names), sizeof(SEXP));

for(int i=0; i<length(SDall); ++i) {
SEXP this = VECTOR_ELT(SDall, i);
if (SIZEOF(this)==0)
Expand Down Expand Up @@ -158,12 +158,12 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
ansloc = 0;
const int *istarts = INTEGER(starts);
const int *iorder = INTEGER(order);
// We just want to set anyNA for later. We do it only once for the whole operation

// We just want to set anyNA for later. We do it only once for the whole operation
// because it is a rare edge case for it to be true. See #4892.
bool anyNA=false, orderedSubset=false;
check_idx(order, length(VECTOR_ELT(dt, 0)), &anyNA, &orderedSubset);

for(int i=0; i<ngrp; ++i) { // even for an empty i table, ngroup is length 1 (starts is value 0), for consistency of empty cases

if (istarts[i]==0 && (i<ngrp-1 || estn>-1)) continue;
Expand Down
6 changes: 3 additions & 3 deletions src/fifelse.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ SEXP fcaseR(SEXP na, SEXP rho, SEXP args) {
"Note that the default argument must be named explicitly, e.g., default=0"), narg);
}
if (narg==0) return R_NilValue;

SEXP cons0 = PROTECT(eval(SEXPPTR_RO(args)[0], rho));
SEXP value0 = PROTECT(eval(SEXPPTR_RO(args)[1], rho)); // value0 will be compared to from loop so leave it protected throughout
SEXPTYPE type0 = TYPEOF(value0);
Expand All @@ -167,7 +167,7 @@ SEXP fcaseR(SEXP na, SEXP rho, SEXP args) {
SEXP tracker = PROTECT(allocVector(INTSXP, len0));
int *restrict p = INTEGER(tracker);
copyMostAttrib(value0, ans);

bool nonna=!isNull(na);
if (nonna) {
if (xlength(na) != 1) {
Expand All @@ -194,7 +194,7 @@ SEXP fcaseR(SEXP na, SEXP rho, SEXP args) {
}
}
}

const int n = narg/2;
for (int i=0; i<n; ++i) {
SEXP cons = PROTECT(i==0 ? cons0 : eval(SEXPPTR_RO(args)[2*i], rho)); // protect cons0 again for easy unprotect at the end of this loop
Expand Down
4 changes: 2 additions & 2 deletions src/forder.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ int StrCmp(SEXP x, SEXP y)
if (x == y) return 0; // same cached pointer (including NA_STRING==NA_STRING)
if (x == NA_STRING) return -1; // x<y
if (y == NA_STRING) return 1; // x>y
return strcmp(CHAR(x), CHAR(y)); // bmerge calls ENC2UTF8 on x and y before passing here
return strcmp(CHAR(x), CHAR(y)); // bmerge calls ENC2UTF8 on x and y before passing here
}

static void cradix_r(SEXP *xsub, int n, int radix)
Expand Down Expand Up @@ -1257,7 +1257,7 @@ SEXP issorted(SEXP x, SEXP by)
// returning NA when NA present, and is multi-column.
// TODO: test in big steps first to return faster if unsortedness is at the end (a common case of rbind'ing data to end)
// These are all sequential access to x, so quick and cache efficient. Could be parallel by checking continuity at batch boundaries.

if (!isNull(by) && !isInteger(by)) STOP(_("Internal error: issorted 'by' must be NULL or integer vector"));
if (isVectorAtomic(x) || length(by)==1) {
// one-column special case is very common so specialize it by avoiding column-type switches inside the row-loop later
Expand Down
4 changes: 2 additions & 2 deletions src/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ static void parse_iso8601_timestamp(FieldParseContext *ctx)
if (!args.noTZasUTC)
goto fail;
// if neither Z nor UTC offset is present, then it's local time and that's not directly supported yet; see news for v1.13.0
// but user can specify that the unmarked datetimes are UTC by passing tz="UTC"
// but user can specify that the unmarked datetimes are UTC by passing tz="UTC"
// if local time is UTC (env variable TZ is "" or "UTC", not unset) then local time is UTC, and that's caught by fread at R level too
}
}
Expand Down Expand Up @@ -2271,7 +2271,7 @@ int freadMain(freadMainArgs _args) {
fun[abs(thisType)](&fctx);
if (*tch!=sep) break;
int8_t thisSize = size[j];
if (thisSize) ((char **) targets)[thisSize] += thisSize; // 'if' for when rereading to avoid undefined NULL+0
if (thisSize) ((char **) targets)[thisSize] += thisSize; // 'if' for when rereading to avoid undefined NULL+0
tch++;
j++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/fread.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef struct freadMainArgs
bool logical01;

bool keepLeadingZeros;

// should datetime with no Z or UTZ-offset be read as UTC?
bool noTZasUTC;

Expand Down
2 changes: 1 addition & 1 deletion src/freadR.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ bool userOverride(int8_t *type, lenOff *colNames, const char *anchor, const int
type[i]=CT_STRING; // e.g. CT_ISO8601_DATE changed to character here so that as.POSIXct treats the date-only as local time in tests 1743.122 and 2150.11
SET_STRING_ELT(colClassesAs, i, tt);
}
} else {
} else {
type[i] = typeEnum[w-1]; // freadMain checks bump up only not down
if (w==NUT) SET_STRING_ELT(colClassesAs, i, tt);
}
Expand Down
8 changes: 4 additions & 4 deletions src/fsort.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ SEXP fsort(SEXP x, SEXP verboseArg) {
// TODO: -0ULL should allow negatives
// avoid twiddle function call as expensive in recent tests (0.34 vs 2.7)
// possibly twiddle once to *ans, then untwiddle at the end in a fast parallel sweep

union {double d; uint64_t u64;} u;
u.d = max;
uint64_t maxULL = u.u64;
Expand Down Expand Up @@ -262,7 +262,7 @@ SEXP fsort(SEXP x, SEXP verboseArg) {
double *restrict myworking = NULL;
// the working memory for the largest group per thread is allocated when the thread receives its first iteration
int myfirstmsb = -1; // for the monotonicity check

#pragma omp for schedule(monotonic_dynamic,1)
// We require here that a thread can never be assigned to an earlier iteration; e.g. threads 0:(nth-1)
// get iterations 0:(nth-1), possibly out of order, then first-come-first-served in order after that.
Expand Down Expand Up @@ -291,7 +291,7 @@ SEXP fsort(SEXP x, SEXP verboseArg) {
if (myfirstmsb==-1 || msb<myfirstmsb) {
failed=true; non_monotonic=true; continue; // # nocov
}

// Depends on msbCounts being sorted largest first before this parallel loop
// Could be significant RAM saving if the largest msb is
// a lot larger than the 2nd largest msb, especially as nth grows to perhaps 128 on X1.
Expand All @@ -317,7 +317,7 @@ SEXP fsort(SEXP x, SEXP verboseArg) {
error(_("Unable to allocate working memory")); // # nocov
}
t[7] = wallclock();

// TODO: parallel sweep to check sorted using <= on original input. Feasible that twiddling messed up.
// After a few years of heavy use remove this check for speed, and move into unit tests.
// It's a perfectly contiguous and cache efficient parallel scan so should be relatively negligible.
Expand Down
2 changes: 1 addition & 1 deletion src/fwriteR.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ SEXP fwriteR(
)
{
if (!isNewList(DF)) error(_("fwrite must be passed an object of type list; e.g. data.frame, data.table"));

fwriteMainArgs args = {0}; // {0} to quieten valgrind's uninitialized, #4639
args.is_gzip = LOGICAL(is_gzip_Arg)[0];
args.bom = LOGICAL(bom_Arg)[0];
Expand Down
2 changes: 1 addition & 1 deletion src/nqrecreateindices.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SEXP nqRecreateIndices(SEXP xo, SEXP len, SEXP indices, SEXP nArg, SEXP nomatch)
ans = PROTECT(allocVector(VECSXP, 2));
SET_VECTOR_ELT(ans, 0, (newstarts = allocVector(INTSXP, n)));
SET_VECTOR_ELT(ans, 1, (newlen = allocVector(INTSXP, n)));

int *inewlen = INTEGER(newlen);
const int *iindices = INTEGER(indices);
const int *ilen = INTEGER(len);
Expand Down
2 changes: 1 addition & 1 deletion src/openmp-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int getDTthreads(const int64_t n, const bool throttle) {
// this is the main getter used by all parallel regions; they specify num_threads(n, true|false).
// Keep this light, simple and robust. initDTthreads() ensures 1 <= DTthreads <= omp_get_num_proc()
// throttle introduced in 1.12.10 (see NEWS item); #4484
// throttle==true : a number of iterations per thread (DTthrottle) is applied before a second thread is utilized
// throttle==true : a number of iterations per thread (DTthrottle) is applied before a second thread is utilized
// throttle==false : parallel region is already pre-chunked such as in fread; e.g. two batches intended for two threads
if (n<1) return 1; // 0 or negative could be deliberate in calling code for edge cases where loop is not intended to run at all
int64_t ans = throttle ? 1+(n-1)/DTthrottle : // 1 thread for n<=1024, 2 thread for n<=2048, etc
Expand Down
30 changes: 15 additions & 15 deletions src/snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int dt_win_snprintf(char *dest, const size_t n, const char *fmt, ...)
strncpy(ch2, strp[i], strl[i]); // write the reordered specifers without the n$ part
ch2 += strl[i];
strcpy(ch2, delim); // includes '\0'
ch2 += NDELIM; // now resting on the '\0'
ch2 += NDELIM; // now resting on the '\0'
}
char *buff = malloc(n); // for the result of the specifiers
if (!buff) {
Expand Down Expand Up @@ -202,46 +202,46 @@ SEXP test_dt_win_snprintf()

dt_win_snprintf(buff, 50, "%1$d %s", 9, "foo");
if (strcmp(buff, "3 some %n$ but not all")) error(_("dt_win_snprintf test %d failed: %s"), 5, buff);

dt_win_snprintf(buff, 50, "%%1$foo%d", 9); // The %1$f is not a specifier because % is doubled
if (strcmp(buff, "%1$foo9")) error(_("dt_win_snprintf test %d failed: %s"), 6, buff);

dt_win_snprintf(buff, 40, "long format string more than n==%d chopped", 40); // regular library (no %n$) chops to 39 chars + '/0'
if (strlen(buff)!=39 || strcmp(buff, "long format string more than n==40 chop")) error(_("dt_win_snprintf test %d failed: %s"), 7, buff);

dt_win_snprintf(buff, 40, "long %3$s %2$s more than n==%1$d chopped", 40, "string", "format"); // same with dt_win_snprintf
if (strlen(buff)!=39 || strcmp(buff, "long format string more than n==40 chop")) error(_("dt_win_snprintf test %d failed: %s"), 8, buff);

int res = dt_win_snprintf(buff, 10, "%4$d%2$d%3$d%5$d%1$d", 111, 222, 33, 44, 555); // fmt longer than n
if (strlen(buff)!=9 || strcmp(buff, "442223355")) error(_("dt_win_snprintf test %d failed: %s"), 9, buff);
if (res!=13) /* should return what would have been written if not chopped */ error(_("dt_win_snprintf test %d failed: %s"), 10, res);

dt_win_snprintf(buff, 39, "%l", 3);
if (strlen(buff)!=38 || strcmp(buff, "0 %l does not end with recognized t")) error(_("dt_win_snprintf test %d failed: %s"), 11, buff);

dt_win_snprintf(buff, 19, "%l", 3);
if (strlen(buff)!=18 || strcmp(buff, "0 %l does not e")) error(_("dt_win_snprintf test %d failed: %s"), 12, buff);

dt_win_snprintf(buff, 50, "%1$d == %0$d", 1, 2);
if (strcmp(buff, "1 %0$ outside range [1,99]")) error(_("dt_win_snprintf test %d failed: %s"), 13, buff);

dt_win_snprintf(buff, 50, "%1$d == %$d", 1, 2);
if (strcmp(buff, "1 %$ outside range [1,99]")) error(_("dt_win_snprintf test %d failed: %s"), 14, buff);

dt_win_snprintf(buff, 50, "%1$d == %100$d", 1, 2);
if (strcmp(buff, "1 %100$ outside range [1,99]")) error(_("dt_win_snprintf test %d failed: %s"), 15, buff);

dt_win_snprintf(buff, 50, "%1$d == %-1$d", 1, 2);
if (strcmp(buff, "1 %-1$ outside range [1,99]")) error(_("dt_win_snprintf test %d failed: %s"), 16, buff);

dt_win_snprintf(buff, 50, "%1$d == %3$d", 1, 2, 3);
if (strcmp(buff, "5 %2$ missing")) error(_("dt_win_snprintf test %d failed: %s"), 17, buff);

dt_win_snprintf(buff, 50, "%1$d == %1$d", 42);
if (strcmp(buff, "2 %1$ appears twice")) error(_("dt_win_snprintf test %d failed: %s"), 18, buff);

dt_win_snprintf(buff, 50, "%1$d + %3$d - %2$d == %3$d", 1, 1, 2);
if (strcmp(buff, "2 %3$ appears twice")) error(_("dt_win_snprintf test %d failed: %s"), 19, buff);

return R_NilValue;
}
8 changes: 4 additions & 4 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool allNA(SEXP x, bool errorForBadType) {
return true;
case CPLXSXP: {
const Rcomplex *xd = COMPLEX(x);
for (int i=0; i<n; ++i) if (!ISNAN_COMPLEX(xd[i])) {
for (int i=0; i<n; ++i) if (!ISNAN_COMPLEX(xd[i])) {
return false;
}
return true;
Expand Down Expand Up @@ -187,7 +187,7 @@ SEXP copyAsPlain(SEXP x) {
// For non-ALTREP this should do the same as R's duplicate().
// Intended for use on columns; to either un-ALTREP them or duplicate shared memory columns; see copySharedColumns() below
// Not intended to be called on a DT VECSXP where a concept of 'deep' might refer to whether the columns are copied

if (isNull(x)) {
// deal with up front because isNewList(R_NilValue) is true
return R_NilValue;
Expand Down Expand Up @@ -245,7 +245,7 @@ void copySharedColumns(SEXP x) {
const SEXP thiscol = xp[i];
savetl[i] = ALTREP(thiscol) ? 0 : TRUELENGTH(thiscol);
SET_TRUELENGTH(thiscol, 0);
}
}
int nShared=0;
for (int i=0; i<ncol; ++i) {
SEXP thiscol = xp[i];
Expand All @@ -258,7 +258,7 @@ void copySharedColumns(SEXP x) {
// 'shared' means a later column shares an earlier column
SET_TRUELENGTH(thiscol, -i-1); // -i-1 so that if, for example, column 3 shares column 1, in iteration 3 we'll know not
// only that the 3rd column is shared with an earlier column, but which one too. Although
// we don't use that information currently, we could do in future.
// we don't use that information currently, we could do in future.
}
}
// now we know nShared and which ones they are (if any), restore original tl back to the unique set of columns
Expand Down

0 comments on commit d8e0fb3

Please sign in to comment.