You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor copyFile() message fragment for ease of translation (#6483)
* Refactor copyFile() message fragment for ease of translation
* Alternative approach: refactor logic outside of copyFile() helper
* missing '}'
* match improved grammar in test
* exact equality to -1.0
voidcopyFile(size_tfileSize, constchar*msg, boolverbose) // only called in very very rare cases
440
+
doublecopyFile(size_tfileSize) // only called in very very rare cases
442
441
{
443
442
doublett=wallclock();
444
-
mmp_copy= (char*)malloc((size_t)fileSize+1/* extra \0 */);
443
+
mmp_copy= (char*)malloc((size_t)fileSize+1/* extra \0 */);
445
444
if (!mmp_copy)
446
-
STOP(_("Unable to allocate %s of contiguous virtual RAM. %s allocation."), filesize_to_str(fileSize), msg);
445
+
return-1.0;
447
446
memcpy(mmp_copy, mmp, fileSize);
448
447
sof=mmp_copy;
449
448
eof= (char*)mmp_copy+fileSize;
450
-
tt=wallclock()-tt;
451
-
if (tt>0.5) DTPRINT(_("Avoidable %.3f seconds. %s time to copy.\n"), tt, msg); // not warning as that could feasibly cause CRAN tests to fail, say, if test machine is heavily loaded
452
-
if (verbose) DTPRINT(_(" File copy in RAM took %.3f seconds.\n"), tt);
449
+
returnwallclock()-tt;
453
450
}
454
451
455
452
@@ -1534,10 +1531,20 @@ int freadMain(freadMainArgs _args) {
1534
1531
// field) since we rely on that logic to avoid the copy below when fileSize$4096==0 but there is a final eol ok.
1535
1532
// TODO: portable way to discover relevant page size. 4096 is lowest common denominator, though, and should suffice.
1536
1533
} else {
1537
-
constchar*msg=_("This file is very unusual: it ends abruptly without a final newline, and also its size is a multiple of 4096 bytes. Please properly end the last row with a newline using for example 'echo >> file' to avoid this ");
1538
-
if (verbose) DTPRINT(_(" File ends abruptly with '%c'. Copying file in RAM. %s copy.\n"), eof[-1], msg);
1534
+
constchar*msg=_("This file is very unusual: it ends abruptly without a final newline, and also its size is a multiple of 4096 bytes. Please properly end the last row with a newline using for example 'echo >> file'");
1535
+
if (verbose)
1536
+
DTPRINT(_(" File ends abruptly with '%c'. Final end-of-line is missing. Copying file in RAM. %s.\n"), eof[-1], msg);
1539
1537
// In future, we may discover a way to mmap fileSize+1 on all OS when fileSize%4096==0, reliably. If and when, this clause can be updated with no code impact elsewhere.
1540
-
copyFile(fileSize, msg, verbose);
1538
+
doubletime_taken=copyFile(fileSize);
1539
+
if (time_taken==-1.0) {
1540
+
if (!verbose)
1541
+
DTPRINT("%s. Attempt to copy file in RAM failed.", msg);
1542
+
STOP(_("Unable to allocate %s of contiguous virtual RAM."), filesize_to_str(fileSize));
1543
+
}
1544
+
if (verbose)
1545
+
DTPRINT(_(" File copy in RAM took %.3f seconds.\n"), time_taken);
1546
+
elseif (time_taken>0.5)
1547
+
DTPRINT(_("Avoidable file copy in RAM took %.3f seconds. %s.\n"), time_taken, msg); // not warning as that could feasibly cause CRAN tests to fail, say, if test machine is heavily loaded
1541
1548
}
1542
1549
}
1543
1550
*_const_cast(eof) ='\0'; // cow page
@@ -1806,10 +1813,20 @@ int freadMain(freadMainArgs _args) {
1806
1813
if (ncol==1&&lastEOLreplaced&& (eof[-1]=='\n'||eof[-1]=='\r')) {
1807
1814
// Multiple newlines at the end are significant in the case of 1-column files only (multiple NA at the end)
1808
1815
if (fileSize%4096==0) {
1809
-
constchar*msg=_("This file is very unusual: it's one single column, ends with 2 or more end-of-line (representing several NA at the end), and is a multiple of 4096, too.");
1810
-
if (verbose) DTPRINT(_(" Copying file in RAM. %s\n"), msg);
1816
+
constchar*msg=_("This file is very unusual: it's one single column, ends with 2 or more end-of-line (representing several NA at the end), and the file size is a multiple of 4096, too");
1817
+
if (verbose)
1818
+
DTPRINT(_(" Copying file in RAM. %s\n"), msg);
1811
1819
ASSERT(mmp_copy==NULL, "mmp has already been copied due to abrupt non-eol ending, so it does not end with 2 or more eol.%s", ""/*dummy arg for macro*/); // #nocov
1812
-
copyFile(fileSize, msg, verbose);
1820
+
doubletime_taken=copyFile(fileSize);
1821
+
if (time_taken==-1.0) {
1822
+
if (!verbose)
1823
+
DTPRINT("%s. Attempt to copy file in RAM failed.", msg);
1824
+
STOP(_("Unable to allocate %s of contiguous virtual RAM."), filesize_to_str(fileSize));
1825
+
}
1826
+
if (verbose)
1827
+
DTPRINT(_(" File copy in RAM took %.3f seconds.\n"), time_taken);
1828
+
elseif (tt>0.5)
1829
+
DTPRINT(_("Avoidable file copy in RAM took %.3f seconds. %s.\n"), time_taken, msg); // not warning as that could feasibly cause CRAN tests to fail, say, if test machine is heavily loaded
0 commit comments