Thread (12 messages) flat view 12 messages, 3 authors, 2016-06-15

Re: [PATCH 6/6] Retain caches of submodule refs

From: Heiko Voigt <hidden>
Date: 2016-06-15 22:51:48

Hi,

On Sat, Aug 13, 2011 at 12:36:29AM +0200, Michael Haggerty wrote:
quoted hunk ↗ jump to hunk
diff --git a/refs.c b/refs.c
index 8d1055d..f02cf94 100644
--- a/refs.c
+++ b/refs.c
...
quoted hunk ↗ jump to hunk
@@ -205,23 +208,28 @@ struct cached_refs *create_cached_refs(const char *submodule)
  */
 static struct cached_refs *get_cached_refs(const char *submodule)
 {
-	if (! submodule) {
-		if (!cached_refs)
-			cached_refs = create_cached_refs(submodule);
-		return cached_refs;
-	} else {
-		if (!submodule_refs)
-			submodule_refs = create_cached_refs(submodule);
-		else
-			/* For now, don't reuse the refs cache for submodules. */
-			clear_cached_refs(submodule_refs);
-		return submodule_refs;
+	struct cached_refs *refs = cached_refs;
+	if (! submodule)
+		submodule = "";
Maybe instead of searching for the main refs store a pointer to them
locally so you can immediately return here. That will keep the
performance when requesting the main refs the same.

If I see it correctly you are always prepending to the linked list and
in case many submodules get cached this could slow down the iteration
over the refs of the main repository.
+	while (refs) {
+		if (!strcmp(submodule, refs->name))
+			return refs;
+		refs = refs->next;
 	}
+
+	refs = create_cached_refs(submodule);
+	refs->next = cached_refs;
+	cached_refs = refs;
+	return refs;
 }
...

Cheers Heiko
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help