[MERGE] Use a dict to access stat cache information from dirstate.

Ian Clatworthy ian.clatworthy at internode.on.net
Wed Oct 24 06:41:28 BST 2007


Robert Collins wrote:
> This changes the stat lookup in dirstates to build a dict once and then
> answer from it; this is noticeably faster.

> Incremental commit 5 new files:
> real    0m25.044s  0m17.150s

Nice.

bb:tweak

> +    def sha1_from_stat(self, path, stat_result, _pack_stat=pack_stat):
> +        """Find a sha1 given a stat lookup."""
> +        return self._get_packed_stat_index().get(_pack_stat(stat_result), None)
> +
> +    def _get_packed_stat_index(self):
> +        """Get a packed_stat index of self._dirblocks."""
> +        if self._packed_stat_index is None:
> +            index = {}
> +            for key, tree_details in self._iter_entries():
> +                if tree_details[0][0] == 'f':
> +                    index.setdefault(tree_details[0][4], tree_details[0][1])
> +            self._packed_stat_index = index
> +        return self._packed_stat_index
> +

I suspect this could be made faster still by:

1. moving the if test into the top method, saving a method call
2. using a temporary variable for tree_details[0]
3. doing a normal 'set' instead of using setdefault.

Is there a particular reason you use setdefault instead of a plain

  index[x] = y

statement? If so, it's not obvious to me which suggests it needs a comment.

For a partial commit, perhaps we should only loop over those entries
instead of all of them as well?

My only other comment is that the creation and clearing of the cache all
look good but I wonder if you should ever be updating it?

Ian C.



More information about the bazaar mailing list