On Mar 28, 11:12am, marti...@google.com (Martin Buchholz) wrote:
-- Subject: Re: RFR-8008118

| My apologies for unrelenting perfectionism - I noticed that we can:
| - colocate the pathv and path in one malloc'ed chunk
| - can discard xstrdup
| - can iterate through path with only one char* pointer.
| 
| Making this code even cleaner, more concise and efficient.


-    for (i = 0; i < count; i++, p++) {
-        pathv[i] = ((*p == ':') || (*p == '\0')) ? "." : p;
-        while (! ((*p == ':') || (*p == '\0')))
-            p++;
-        *p = '\0';
-     }
-     pathv[count] = NULL;

+     for (i = 0; (pathv[i] = strsep(&p, ":")) != NULL; i++)
+       if (!pathv[i][0])
+               pathv[i] = ".";

christos

Reply via email to