git-svn: make Git::SVN::Fetcher a separate file
[gitweb.git] / refs.c
diff --git a/refs.c b/refs.c
index d6bdb47ad61dc5e7eb1c786dd4115e17bdb2aab7..010ed07e33d90cbdae4511013319a129c1201ca9 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -273,6 +273,12 @@ static void add_entry_to_dir(struct ref_dir *dir, struct ref_entry *entry)
 {
        ALLOC_GROW(dir->entries, dir->nr + 1, dir->alloc);
        dir->entries[dir->nr++] = entry;
+       /* optimize for the case that entries are added in order */
+       if (dir->nr == 1 ||
+           (dir->nr == dir->sorted + 1 &&
+            strcmp(dir->entries[dir->nr - 2]->name,
+                   dir->entries[dir->nr - 1]->name) < 0))
+               dir->sorted = dir->nr;
 }
 
 /*