Revision a3b3c9c916298199e4a80afccc2e14b69e5d6d42 authored by Junio C Hamano on 16 February 2017, 22:45:13 UTC, committed by Junio C Hamano on 16 February 2017, 22:45:13 UTC
"ls-files" run with pathspec has been micro-optimized to avoid
having to memmove(3) unnecessary bytes.

* rs/ls-files-partial-optim:
  ls-files: move only kept cache entries in prune_cache()
  ls-files: pass prefix length explicitly to prune_cache()
2 parent s 0078a75 + 96f6d3f
Raw File
mru.c
#include "cache.h"
#include "mru.h"

void mru_append(struct mru *mru, void *item)
{
	struct mru_entry *cur = xmalloc(sizeof(*cur));
	cur->item = item;
	cur->prev = mru->tail;
	cur->next = NULL;

	if (mru->tail)
		mru->tail->next = cur;
	else
		mru->head = cur;
	mru->tail = cur;
}

void mru_mark(struct mru *mru, struct mru_entry *entry)
{
	/* If we're already at the front of the list, nothing to do */
	if (mru->head == entry)
		return;

	/* Otherwise, remove us from our current slot... */
	if (entry->prev)
		entry->prev->next = entry->next;
	if (entry->next)
		entry->next->prev = entry->prev;
	else
		mru->tail = entry->prev;

	/* And insert us at the beginning. */
	entry->prev = NULL;
	entry->next = mru->head;
	if (mru->head)
		mru->head->prev = entry;
	mru->head = entry;
}

void mru_clear(struct mru *mru)
{
	struct mru_entry *p = mru->head;

	while (p) {
		struct mru_entry *to_free = p;
		p = p->next;
		free(to_free);
	}
	mru->head = mru->tail = NULL;
}
back to top