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.
This commit is contained in:
@@ -378,8 +378,7 @@ char *do_browse_from(const char *inpath)
|
|||||||
beep();
|
beep();
|
||||||
napms(1200);
|
napms(1200);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else
|
}
|
||||||
snuggly_fit(&path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1348,8 +1348,7 @@ char *get_full_path(const char *origpath)
|
|||||||
if (strcmp(d_here, "/") != 0) {
|
if (strcmp(d_here, "/") != 0) {
|
||||||
d_here = charealloc(d_here, strlen(d_here) + 2);
|
d_here = charealloc(d_here, strlen(d_here) + 2);
|
||||||
strcat(d_here, "/");
|
strcat(d_here, "/");
|
||||||
} else
|
}
|
||||||
snuggly_fit(&d_here);
|
|
||||||
/* Otherwise, set d_here to "". */
|
/* Otherwise, set d_here to "". */
|
||||||
} else {
|
} else {
|
||||||
d_here = mallocstrcpy(NULL, "");
|
d_here = mallocstrcpy(NULL, "");
|
||||||
@@ -1410,8 +1409,7 @@ char *get_full_path(const char *origpath)
|
|||||||
if (strcmp(d_there, "/") != 0) {
|
if (strcmp(d_there, "/") != 0) {
|
||||||
d_there = charealloc(d_there, strlen(d_there) + 2);
|
d_there = charealloc(d_there, strlen(d_there) + 2);
|
||||||
strcat(d_there, "/");
|
strcat(d_there, "/");
|
||||||
} else
|
}
|
||||||
snuggly_fit(&d_there);
|
|
||||||
/* Otherwise, make sure that we return NULL. */
|
/* Otherwise, make sure that we return NULL. */
|
||||||
} else {
|
} else {
|
||||||
path_only = TRUE;
|
path_only = TRUE;
|
||||||
@@ -1528,6 +1526,8 @@ void init_operating_dir(void)
|
|||||||
/* If the operating directory is inaccessible, fail. */
|
/* If the operating directory is inaccessible, fail. */
|
||||||
if (full_operating_dir == NULL || chdir(full_operating_dir) == -1)
|
if (full_operating_dir == NULL || chdir(full_operating_dir) == -1)
|
||||||
die("Invalid operating directory\n");
|
die("Invalid operating directory\n");
|
||||||
|
|
||||||
|
snuggly_fit(full_operating_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check to see if we're inside the operating directory. Return FALSE
|
/* Check to see if we're inside the operating directory. Return FALSE
|
||||||
@@ -1618,6 +1618,7 @@ void init_backup_dir(void)
|
|||||||
} else {
|
} else {
|
||||||
free(backup_dir);
|
free(backup_dir);
|
||||||
backup_dir = full_backup_dir;
|
backup_dir = full_backup_dir;
|
||||||
|
snuggly_fit(backup_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* !NANO_TINY */
|
#endif /* !NANO_TINY */
|
||||||
|
|||||||
@@ -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. */
|
/* 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);
|
charmove(top->data, top->data + top_x, strlen(top->data) - top_x + 1);
|
||||||
snuggly_fit(&top->data);
|
|
||||||
|
|
||||||
/* Return the partition. */
|
/* Return the partition. */
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
Reference in New Issue
Block a user