[PATCH v2 4/5] resolv: Optimize inet_ntop

Wilco Dijkstra Wilco.Dijkstra@arm.com
Thu Jun 5 14:04:02 GMT 2025


Hi Adhemerval,

A few quick nits:

+static inline char *
+put_uint8 (uint8_t word, char *tp)
 {
+  int s = 1;

Why not create and update a result pointer instead, like char *res = tp + 1?

+  if (word >= 10)
     {
+      if (word >= 100)
+	{
+	  tp[2] = '0' + word % 10;
+	  word /= 10;
+	  s += 1;
+	}
+
+      tp[1] = '0' + word % 10;
+      word /= 10;
+      s += 1;
     }
+  *tp = '0' + word % 10;

The % 10 is redundant.

+  return tp + s;
 }

Cheers,
Wilco


More information about the Libc-alpha mailing list