diff options
author | Steve Frécinaux <code@istique.net> | 2008-09-05 21:51:14 +0200 |
---|---|---|
committer | Steve Frécinaux <code@istique.net> | 2008-09-05 22:47:37 +0200 |
commit | b377c07200392ac35a6ed668673451d3c9b1f5c7 (patch) | |
tree | 59d864deb2049863dc4d989927c360851ca4c280 /lib/git/tree.py | |
parent | 590638f9a56440a2c41cc04f52272ede04c06a43 (diff) | |
download | gitpython-b377c07200392ac35a6ed668673451d3c9b1f5c7.tar.gz |
Use a dictionnary for tree contents
It seems more natural to use a dictionnary for directories, since we
usually want to access them by name, and entry order is not relevant.
Also, finding a particular blob given its name is O(1) instead of O(N).
Diffstat (limited to 'lib/git/tree.py')
-rw-r--r-- | lib/git/tree.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/git/tree.py b/lib/git/tree.py index f1aa0b3b..86e893ef 100644 --- a/lib/git/tree.py +++ b/lib/git/tree.py @@ -32,13 +32,13 @@ class Tree(LazyMixin): def construct_initialize(self, repo, id, text): self.repo = repo self.id = id - self.contents = [] + self.contents = {} self.__baked__ = False for line in text.splitlines(): - self.contents.append(self.content_from_string(self.repo, line)) - - self.contents = [c for c in self.contents if c is not None] + obj = self.content_from_string(self.repo, line) + if obj: + self.contents[obj.name] = obj self.__bake_it__() return self @@ -84,8 +84,7 @@ class Tree(LazyMixin): Returns ``GitPython.Blob`` or ``GitPython.Tree`` or ``None`` if not found """ - contents = [c for c in self.contents if c.name == file] - return contents and contents[0] or None + return self.contents.get(file) @property def basename(self): |