here (char prev) is copy semantic,but really faster than (char *prev) ?
tip:i'm learning hc, forgive my interesting...
hc->src->filehandling.c:
u64 count_lines (FILE *fd)
{
u64 cnt = 0;
char *buf = (char *) hcmalloc (HCBUFSIZ_LARGE + 1);
char prev = '\n';
while (!feof (fd))
{
size_t nread = fread (buf, sizeof (char), HCBUFSIZ_LARGE, fd);
if (nread < 1) continue;
size_t i;
for (i = 0; i < nread; i++)
{
if (prev == '\n') cnt++;
prev = buf[i];
}
}
hcfree (buf);
return cnt;
}
tip:i'm learning hc, forgive my interesting...
hc->src->filehandling.c:
u64 count_lines (FILE *fd)
{
u64 cnt = 0;
char *buf = (char *) hcmalloc (HCBUFSIZ_LARGE + 1);
char prev = '\n';
while (!feof (fd))
{
size_t nread = fread (buf, sizeof (char), HCBUFSIZ_LARGE, fd);
if (nread < 1) continue;
size_t i;
for (i = 0; i < nread; i++)
{
if (prev == '\n') cnt++;
prev = buf[i];
}
}
hcfree (buf);
return cnt;
}