tweaks: avoid a few needless reallocations

Most of these variables are freed moments later -- reallocating
them is thus a waste of time.
master
Benno Schulenberg 2017-03-20 13:01:37 +01:00
parent f48e15f2a3
commit d42f71a2ef
6 changed files with 11 additions and 12 deletions

View File

@ -587,7 +587,7 @@ void browser_refresh(void)
/* Make sure info takes up no more than infomaxlen columns. */
infolen = strlenpt(info);
if (infolen > infomaxlen) {
null_at(&info, actual_x(info, infomaxlen));
info[actual_x(info, infomaxlen)] = '\0';
infolen = infomaxlen;
}

View File

@ -1028,9 +1028,8 @@ char *get_next_filename(const char *name, const char *suffix)
sprintf(buf + wholenamelen, ".%lu", i);
}
/* We get here only if there is no possible save file. Blank out
* the filename to indicate this. */
null_at(&buf, 0);
/* There is no possible save file: blank out the filename. */
*buf = '\0';
return buf;
}
@ -1228,7 +1227,7 @@ char *get_full_path(const char *origpath)
/* How often we've tried climbing back up the tree. */
struct stat fileinfo;
char *currentdir, *d_here, *d_there, *d_there_file = NULL;
const char *last_slash;
char *last_slash;
bool path_only;
if (origpath == NULL)
@ -1294,7 +1293,7 @@ char *get_full_path(const char *origpath)
d_there_file = mallocstrcpy(NULL, last_slash + 1);
/* Remove the filename portion of the answer from d_there. */
null_at(&d_there, last_slash - d_there + 1);
*(last_slash + 1) = '\0';
/* Go to the path specified in d_there. */
if (chdir(d_there) == -1) {
@ -2503,7 +2502,7 @@ char **cwd_tab_completion(const char *buf, bool allow_files, size_t
const struct dirent *nextdir;
*num_matches = 0;
null_at(&dirname, buf_len);
dirname[buf_len] = '\0';
/* If there's a / in the name, split out filename and directory parts. */
slash = strrchr(dirname, '/');

View File

@ -228,7 +228,7 @@ partition *partition_filestruct(filestruct *top, size_t top_x,
p->bot_data = mallocstrcpy(NULL, bot->data + bot_x);
/* Remove all text after bot_x at the bottom of the partition. */
null_at(&bot->data, bot_x);
bot->data[bot_x] = '\0';
/* 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);

View File

@ -296,7 +296,7 @@ void do_statusbar_cut_text(void)
if (!ISSET(CUT_TO_END))
statusbar_x = 0;
null_at(&answer, statusbar_x);
answer[statusbar_x] = '\0';
update_the_statusbar();
}
@ -637,7 +637,7 @@ int do_prompt(bool allow_tabs, bool allow_files,
vsnprintf(prompt, COLS * mb_cur_max(), msg, ap);
va_end(ap);
/* Reserve five columns for colon plus angles plus answer, ":<aa>". */
null_at(&prompt, actual_x(prompt, (COLS < 5) ? 0 : COLS - 5));
prompt[actual_x(prompt, (COLS < 5) ? 0 : COLS - 5)] = '\0';
func = acquire_an_answer(&retval, allow_tabs, allow_files, &listed,
#ifndef DISABLE_HISTORIES

View File

@ -1046,7 +1046,7 @@ void do_find_bracket(void)
bracket_set = charalloc((mb_cur_max() * 2) + 1);
strncpy(bracket_set, ch, ch_len);
strncpy(bracket_set + ch_len, wanted_ch, wanted_ch_len);
null_at(&bracket_set, ch_len + wanted_ch_len);
bracket_set[ch_len + wanted_ch_len] = '\0';
found_ch = charalloc(mb_cur_max() + 1);

View File

@ -1226,7 +1226,7 @@ void add_undo(undo_type action)
char *char_buf = charalloc(mb_cur_max() + 1);
int char_len = parse_mbchar(&openfile->current->data[u->begin],
char_buf, NULL);
null_at(&char_buf, char_len);
char_buf[char_len] = '\0';
u->strdata = char_buf;
if (u->type == BACK)
u->mark_begin_x += char_len;