question for
#1
Shocked 
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;
}


Messages In This Thread
question for - by alysa - 05-09-2017, 10:00 AM
RE: question for - by undeath - 05-09-2017, 11:07 AM
RE: question for - by alysa - 05-09-2017, 01:05 PM