Commit b7cd37e556aee40e0c6129a18850576cc7e9f25d

Stefan Sperling 2018-11-19T00:05:48

eliminate strlen() in got_object_id_by_path()

diff --git a/lib/object.c b/lib/object.c
index 7257f45..0826de5 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -808,7 +808,7 @@ got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
 	struct got_tree_object *tree = NULL;
 	struct got_tree_entry *te = NULL;
 	const char *seg, *s;
-	size_t seglen, len = strlen(path);
+	size_t seglen;
 
 	*id = NULL;
 
@@ -834,15 +834,13 @@ got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
 
 	s = path;
 	s++; /* skip leading '/' */
-	len--;
 	seg = s;
 	seglen = 0;
-	while (len > 0) {
+	while (*s) {
 		struct got_tree_object *next_tree;
 
 		if (*s != '/') {
 			s++;
-			len--;
 			seglen++;
 			if (*s)
 				continue;
@@ -854,13 +852,12 @@ got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
 			goto done;
 		}
 
-		if (len == 0)
+		if (*s == '\0')
 			break;
 
 		seg = s + 1;
 		seglen = 0;
 		s++;
-		len--;
 		if (*s) {
 			err = got_object_open_as_tree(&next_tree, repo,
 			    te->id);