From d7af590c6bd2ada5feaee4856e4b4bbf230d474b Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Fri, 16 Dec 2016 21:28:28 +0100
Subject: [PATCH] memory: don't bother making a snug fit for things that will
 be freed soon

Most full paths are needed only temporarily and will be freed within
milliseconds.  Only 'full_operating_dir' and 'backup_dir' continue to
exist for the whole current session.  Any partition, too, will soon be
unpartitioned, so the extra reallocation is just a waste of time.
---
 src/browser.c | 3 +--
 src/files.c   | 9 +++++----
 src/nano.c    | 1 -
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/browser.c b/src/browser.c
index 280de404..9824a896 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -378,8 +378,7 @@ char *do_browse_from(const char *inpath)
 		beep();
 		napms(1200);
 		return NULL;
-	    } else
-		snuggly_fit(&path);
+	    }
 	}
     }
 
diff --git a/src/files.c b/src/files.c
index 147a26cb..80fbefeb 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1348,8 +1348,7 @@ char *get_full_path(const char *origpath)
 	if (strcmp(d_here, "/") != 0) {
 	    d_here = charealloc(d_here, strlen(d_here) + 2);
 	    strcat(d_here, "/");
-	} else
-	    snuggly_fit(&d_here);
+	}
     /* Otherwise, set d_here to "". */
     } else {
 	d_here = mallocstrcpy(NULL, "");
@@ -1410,8 +1409,7 @@ char *get_full_path(const char *origpath)
 		if (strcmp(d_there, "/") != 0) {
 		    d_there = charealloc(d_there, strlen(d_there) + 2);
 		    strcat(d_there, "/");
-		} else
-		    snuggly_fit(&d_there);
+		}
 	    /* Otherwise, make sure that we return NULL. */
 	    } else {
 		path_only = TRUE;
@@ -1528,6 +1526,8 @@ void init_operating_dir(void)
     /* If the operating directory is inaccessible, fail. */
     if (full_operating_dir == NULL || chdir(full_operating_dir) == -1)
 	die("Invalid operating directory\n");
+
+    snuggly_fit(full_operating_dir);
 }
 
 /* Check to see if we're inside the operating directory.  Return FALSE
@@ -1618,6 +1618,7 @@ void init_backup_dir(void)
     } else {
 	free(backup_dir);
 	backup_dir = full_backup_dir;
+	snuggly_fit(backup_dir);
     }
 }
 #endif /* !NANO_TINY */
diff --git a/src/nano.c b/src/nano.c
index d5c4c91b..02732238 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -227,7 +227,6 @@ partition *partition_filestruct(filestruct *top, size_t top_x,
 
     /* Remove all text before top_x at the top of the partition. */
     charmove(top->data, top->data + top_x, strlen(top->data) - top_x + 1);
-    snuggly_fit(&top->data);
 
     /* Return the partition. */
     return p;
-- 
GitLab