Skip to content

Commit

Permalink
simplify and optimize read function
Browse files Browse the repository at this point in the history
  • Loading branch information
ikozyris committed Aug 17, 2024
1 parent 5c9be0f commit 166f733
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions utils/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,14 @@ void read_fread(FILE *fi)
long res;
while ((a = fread(tmp, sizeof(tmp[0]), SZ, fi))) {
tmp[a] = 0;
res = whereis(tmp, '\n');
if (res > 0) { // found newline
while ((res = whereis(tmp + j, '\n')) > -1) {
apnd_s(*it, tmp + j, res);
j += res;
if (++curnum >= txt_cpt) {
txt_cpt *= 2;
text.resize(txt_cpt);
}
++it;
while ((res = whereis(tmp + j, '\n')) > -1) {
apnd_s(*it, tmp + j, res);
j += res;
if (++curnum >= txt_cpt) {
txt_cpt *= 2;
text.resize(txt_cpt);
}
++it;
}
// if last character is not a newline
apnd_s(*it, tmp + j, a - j);
Expand Down

0 comments on commit 166f733

Please sign in to comment.