Commits

Greg Ward committed ccd7784

hg: replace sum_bytes() with non_zero().

Why do it implicitly and imperfectly when we can do it explicitly and
correctly?

Comments (0)

Files changed (1)

     return isdir(".hg");
 }
 
+/* return true if data contains any non-zero bytes */
 static int
-sum_bytes(const unsigned char *data, int size)
+non_zero(const unsigned char *data, int size)
 {
-    int i, sum = 0;
-    for (i = 0; i < size; ++i) {
-        sum += data[i];
+    int i;
+    for (i = 0; i < size; i++) {
+       if (data[i] != 0)
+           return 1;
     }
-    return sum;
+    return 0;
 }
 
 static int
     char *p = destbuf;
 
     // first parent
-    if (sum_bytes((unsigned char *) parent_nodes, NODEID_LEN)) {
+    if (non_zero((unsigned char *) parent_nodes, NODEID_LEN)) {
         p += put_nodeid(p, parent_nodes);
     }
 
     // second parent
-    if (sum_bytes((unsigned char *) parent_nodes + NODEID_LEN, NODEID_LEN)) {
+    if (non_zero((unsigned char *) parent_nodes + NODEID_LEN, NODEID_LEN)) {
         *p++ = ',';
         p += put_nodeid(p, parent_nodes + NODEID_LEN);
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.