Exemplo n.º 1
0
/* Reduces amount of memory taken by the history.  The new_len specifies new
 * size of the history, while removed_count parameter designates number of
 * removed elements. */
static void
decrease_history(size_t new_len, size_t removed_count)
{
	reduce_view_history(&lwin, new_len);
	reduce_view_history(&rwin, new_len);

	hist_trunc(&cfg.search_hist, new_len, removed_count);
	hist_trunc(&cfg.cmd_hist, new_len, removed_count);
	hist_trunc(&cfg.prompt_hist, new_len, removed_count);
	hist_trunc(&cfg.filter_hist, new_len, removed_count);
}
Exemplo n.º 2
0
void
hists_resize(int new_size)
{
	const int old_size = curr_stats.history_size;
	const int delta = new_size - old_size;

	if(new_size <= 0)
	{
		hist_reset(&curr_stats.search_hist, old_size);
		hist_reset(&curr_stats.cmd_hist, old_size);
		hist_reset(&curr_stats.prompt_hist, old_size);
		hist_reset(&curr_stats.filter_hist, old_size);
		curr_stats.history_size = 0;
		return;
	}

	curr_stats.history_size = new_size;

	if(delta < 0)
	{
		hist_trunc(&curr_stats.search_hist, new_size, -delta);
		hist_trunc(&curr_stats.cmd_hist, new_size, -delta);
		hist_trunc(&curr_stats.prompt_hist, new_size, -delta);
		hist_trunc(&curr_stats.filter_hist, new_size, -delta);
	}

	curr_stats.cmd_hist.items = reallocarray(curr_stats.cmd_hist.items, new_size,
			sizeof(char *));
	curr_stats.search_hist.items = reallocarray(curr_stats.search_hist.items,
			new_size, sizeof(char *));
	curr_stats.prompt_hist.items = reallocarray(curr_stats.prompt_hist.items,
			new_size, sizeof(char *));
	curr_stats.filter_hist.items = reallocarray(curr_stats.filter_hist.items,
			new_size, sizeof(char *));

	if(delta > 0)
	{
		const size_t str_item_len = sizeof(char *)*delta;

		memset(curr_stats.cmd_hist.items + old_size, 0, str_item_len);
		memset(curr_stats.search_hist.items + old_size, 0, str_item_len);
		memset(curr_stats.prompt_hist.items + old_size, 0, str_item_len);
		memset(curr_stats.filter_hist.items + old_size, 0, str_item_len);
	}
}