Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed improvement file lines #1623

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/basic_fun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,7 @@
return res;
}

//GD: cannot be made faster if we keep using std::string . Performance is not good wrt idl.
BaseGDL* strjoin(EnvT* e) {
SizeT nParam = e->NParam(1);

Expand Down Expand Up @@ -7282,16 +7283,18 @@
if (regex && e->KeywordPresent(ESCAPEIx)) e->Throw("Conflicting keywords.");
if (foldCaseKW && e->KeywordPresent(ESCAPEIx)) e->Throw("Conflicting keywords.");

e->AssureStringScalarKWIfPresent(ESCAPEIx, escape);
vector<long> escList;
long pos = 0;
while (pos != string::npos) {
pos = stringIn.find_first_of(escape, pos);
if (pos != string::npos) {
escList.push_back(pos + 1); // remember escaped char
pos += 2; // skip escaped char
}
}
if (e->KeywordSet(ESCAPEIx)) {
e->AssureStringScalarKWIfPresent(ESCAPEIx, escape); //must be a singleton.

Check warning on line 7288 in src/basic_fun.cpp

View check run for this annotation

Codecov / codecov/patch

src/basic_fun.cpp#L7288

Added line #L7288 was not covered by tests
size_t pos = 0;
while (pos != std::string::npos) {
pos = stringIn.find_first_of(escape, pos);
if (pos != string::npos) {
escList.push_back(pos + 1); // remember escaped char
pos += 2; // skip escaped char

Check warning on line 7294 in src/basic_fun.cpp

View check run for this annotation

Codecov / codecov/patch

src/basic_fun.cpp#L7293-L7294

Added lines #L7293 - L7294 were not covered by tests
}
}
}
vector<long>::iterator escBeg = escList.begin();
vector<long>::iterator escEnd = escList.end();

Expand Down
14 changes: 7 additions & 7 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,19 +2097,19 @@ static void PathSearch( FileListT& fileList, const DString& pathSpec,
char* newinput=(char*) malloc(BUFSIZ);
char lastchar = 0;
SizeT lines;
FILE* fd = NULL;
int fd = 0;
for (SizeT i = 0; i < nEl; ++i) {
std::string fname = (*p0S)[i];

if (!noExp) WordExp(fname);

if ((fd = fopen(fname.c_str(), "r")) == NULL) {
if ((fd = open(fname.c_str(), O_RDONLY)) == -1) {
e->Throw("Could not open file for reading "); // + p0[i]);
}
lines = 0;
int count=0;
count=fread(newinput, 1, BUFSIZ, fd);
while (count != 0) {
count=read(fd, newinput, BUFSIZ);
while (count > 0) {
for (int i = 0; i < count; ++i) {
if (newinput[i] == '\n') {
lines++;
Expand All @@ -2118,10 +2118,10 @@ static void PathSearch( FileListT& fileList, const DString& pathSpec,

lastchar = newinput[i];
}
count = fread(newinput, 1, BUFSIZ, fd);
count=read(fd, newinput, BUFSIZ);
}

fclose(fd);
close(fd);
if (lastchar != '\n' && lastchar != '\r') lines++;

(*res)[ i] = lines;
Expand Down Expand Up @@ -2615,7 +2615,7 @@ static int copy_basic(const char *source, const char *dest)
status = chmod(dest, srcmode);

return status;
}
}

static void FileCopy( FileListT& fileList, const DString& destdir,
bool overwrite, bool recursive=false,
Expand Down
Loading