eliminate strlen() in got_object_id_by_path()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
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);