: asapien/signet

commit 976fc255515a321af5d7310baf8a6a738698b40b
parent 785190196777ebf3dcdd025c097a59e2215c19cd
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 05:36:20 +0530

Inline validators is_uuid, is_safe_name, is_safe_relpath

Convert three validation functions from util.c to static inline in util.h.
Zero call overhead, compiler inlines automatically. Removes 45 lines of
function boilerplate from util.c while maintaining identical semantics.

Functions still defined once, called 15+ times across signet-api.c—
inlining eliminates 15+ call overhead costs per request.

Skipped: nothing. Add when: performance profiling shows validation bottleneck
(unlikely; these are microseconds on <1KB inputs).

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2 files changed, 33 insertions(+), 52 deletions(-)
M
src/util.c
|
48
+-----------------------------------------------
M
src/util.h
|
37
++++++++++++++++++++++++++++++++-----
diff --git a/src/util.c b/src/util.c
@@ -238,53 +238,7 @@ file_exists(const char *path)
 	return stat(path, &st) == 0 && S_ISREG(st.st_mode);
 }
 
-/* --- validation ------------------------------------------------------------ */
-
-int
-is_uuid(const char *s)
-{
-	int i;
-
-	if (s == NULL || strlen(s) != 36)
-		return 0;
-	for (i = 0; i < 36; i++) {
-		if (i == 8 || i == 13 || i == 18 || i == 23) {
-			if (s[i] != '-')
-				return 0;
-		} else if (!isxdigit((unsigned char)s[i]))
-			return 0;
-	}
-	return 1;
-}
-
-int
-is_safe_name(const char *s)
-{
-	size_t i, n;
-
-	if (s == NULL || (n = strlen(s)) == 0 || n > 64 || s[0] == '.')
-		return 0;
-	for (i = 0; i < n; i++)
-		if (!isalnum((unsigned char)s[i]) && s[i] != '.' &&
-		    s[i] != '_' && s[i] != '-')
-			return 0;
-	return 1;
-}
-
-int
-is_safe_relpath(const char *s)
-{
-	const char *p;
-
-	if (s == NULL || *s == '\0' || *s == '/' || strlen(s) > 255)
-		return 0;
-	if (strstr(s, "..") != NULL)
-		return 0;
-	for (p = s; *p; p++)
-		if ((unsigned char)*p < 0x20 || *p == '\\')
-			return 0;
-	return 1;
-}
+/* validators now inlined in util.h */
 
 uint32_t
 utf8_next(const char **sp)
diff --git a/src/util.h b/src/util.h
@@ -18,11 +18,38 @@ int copy_file(const char *src, const char *dst);
 int write_file(const char *path, const void *buf, size_t len, int mode);
 int file_exists(const char *path);
 
-int is_uuid(const char *s);
-/* usernames, series codes: [A-Za-z0-9._-]{1,64}, not starting with '.' */
-int is_safe_name(const char *s);
-/* relative path inside the DAM: no leading '/', no "..", no control chars */
-int is_safe_relpath(const char *s);
+#include <ctype.h>
+#include <string.h>
+
+/* inlined validators: zero call overhead */
+static inline int is_uuid(const char *s) {
+	int i;
+	if (s == NULL || strlen(s) != 36) return 0;
+	for (i = 0; i < 36; i++) {
+		if (i == 8 || i == 13 || i == 18 || i == 23) {
+			if (s[i] != '-') return 0;
+		} else if (!isxdigit((unsigned char)s[i])) return 0;
+	}
+	return 1;
+}
+
+static inline int is_safe_name(const char *s) {
+	size_t i, n;
+	if (s == NULL || (n = strlen(s)) == 0 || n > 64 || s[0] == '.') return 0;
+	for (i = 0; i < n; i++)
+		if (!isalnum((unsigned char)s[i]) && s[i] != '.' && s[i] != '_' && s[i] != '-')
+			return 0;
+	return 1;
+}
+
+static inline int is_safe_relpath(const char *s) {
+	const char *p;
+	if (s == NULL || *s == '\0' || *s == '/' || strlen(s) > 255) return 0;
+	if (strstr(s, "..") != NULL) return 0;
+	for (p = s; *p; p++)
+		if ((unsigned char)*p < 0x20 || *p == '\\') return 0;
+	return 1;
+}
 
 /* decode one UTF-8 code point, advance *s; returns 0xFFFD on bad input */
 uint32_t utf8_next(const char **s);