Skip to content

Commit

Permalink
Release build speedup SREAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter-Jacob committed Mar 5, 2023
1 parent f60135c commit 0716b7c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/rxmvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3184,7 +3184,8 @@ void R_sarray(int func) {
}

void R_sread(int func) {
int sname,recs=0,ssize,smax,ii;
int sname,recs=0,ssize,ii;
long smax,off1,off2;
FILE *fk; // file handle
char record[16385];
char *pos;
Expand All @@ -3204,15 +3205,18 @@ void R_sread(int func) {
Licpy(ARGR, -1);
return;
}
off1=ftell(fk); // begin offset
for (;;) {
bzero(record,sizeof(record));
fgets(record, sizeof(record)-1, fk);
if(feof(fk)) break;
smax=sizeof(record);
for (ii = sizeof(record); ii>=0; ii--) {
off2=ftell(fk); // new current offset
smax=off2-off1; // this is the reclen
off1=off2;

for (ii = smax+1; ii>=0; ii--) { // start behind reclen, to see if there is /n
if (record[ii]=='\n') {
record[ii] = 0;
smax=ii;
break;
}
}
Expand All @@ -3221,12 +3225,9 @@ void R_sread(int func) {
if (record[ii]=='\n') record[ii]=' ';
else if(record[ii]=='\0') record[ii]=' ';
}

// change LF into x'0'
// if ((pos = strchr(record, '\n')) != NULL) *pos = '\0';
// skip trailing blanks
for (ii = strlen(record); ii >= 0; ii--) {
if (record[ii - 1] == ' ') record[ii - 1] = 0;
for (ii = smax+1; ii >= 0; ii--) {
if (record[ii] == ' ') record[ii] = 0;
else break;
}

Expand All @@ -3235,7 +3236,6 @@ void R_sread(int func) {
else ssize=ssize+2000;
sarray[sname] = REALLOC((void *) sarray[sname], ssize * sizeof(char *));
sindex= (char **) sarray[sname];
// printf("ReAlloc %d %d %x\n",recs,ssize,sarray[sname]);
sindxhi[sname]=ssize;
} // else printf("fits in %d %s\n",recs,record);
snew(recs, record, 0);
Expand Down

0 comments on commit 0716b7c

Please sign in to comment.