Просмотр исходного кода

Remove python3 special casing.

It's not clear that using xrange or .iteritems are actually significantly
faster than range respectively .items on the small lists we use them on.
Jelmer Vernooij 10 лет назад
Родитель
Сommit
41bdaf1e78

+ 1 - 1
dulwich/contrib/swift.py

@@ -126,7 +126,7 @@ class PackInfoObjectStoreIterator(GreenThreadsObjectStoreIterator):
 
 
     def __len__(self):
     def __len__(self):
         while len(self.finder.objects_to_send):
         while len(self.finder.objects_to_send):
-            for _ in xrange(0, len(self.finder.objects_to_send)):
+            for _ in range(0, len(self.finder.objects_to_send)):
                 sha = self.finder.next()
                 sha = self.finder.next()
                 self._shas.append(sha)
                 self._shas.append(sha)
         return len(self._shas)
         return len(self._shas)

+ 3 - 3
dulwich/contrib/test_swift.py

@@ -193,7 +193,7 @@ def create_commit(data, marker='Default', blob=None):
 
 
 def create_commits(length=1, marker='Default'):
 def create_commits(length=1, marker='Default'):
     data = []
     data = []
-    for i in xrange(0, length):
+    for i in range(0, length):
         _marker = "%s_%s" % (marker, i)
         _marker = "%s_%s" % (marker, i)
         blob, tree, tag, cmt = create_commit(data, _marker)
         blob, tree, tag, cmt = create_commit(data, _marker)
         data.extend([blob, tree, tag, cmt])
         data.extend([blob, tree, tag, cmt])
@@ -449,11 +449,11 @@ class TestPackInfoLoadDump(TestCase):
 #    def test_pack_info_perf(self):
 #    def test_pack_info_perf(self):
 #        dump_time = []
 #        dump_time = []
 #        load_time = []
 #        load_time = []
-#        for i in xrange(0, 100):
+#        for i in range(0, 100):
 #            start = time()
 #            start = time()
 #            dumps = swift.pack_info_create(self.pack_data, self.pack_index)
 #            dumps = swift.pack_info_create(self.pack_data, self.pack_index)
 #            dump_time.append(time() - start)
 #            dump_time.append(time() - start)
-#        for i in xrange(0, 100):
+#        for i in range(0, 100):
 #            start = time()
 #            start = time()
 #            pack_infos = swift.load_pack_info('', file=BytesIO(dumps))
 #            pack_infos = swift.load_pack_info('', file=BytesIO(dumps))
 #            load_time.append(time() - start)
 #            load_time.append(time() - start)

+ 6 - 14
dulwich/diff_tree.py

@@ -27,14 +27,6 @@ from io import BytesIO
 from itertools import chain
 from itertools import chain
 import stat
 import stat
 
 
-if sys.version_info[0] == 3:
-    xrange = range
-    izip = zip
-    iteritems = lambda d: d.items()
-else:
-    from itertools import izip
-    iteritems = lambda d: d.iteritems()
-
 from dulwich.objects import (
 from dulwich.objects import (
     S_ISGITLINK,
     S_ISGITLINK,
     TreeEntry,
     TreeEntry,
@@ -111,9 +103,9 @@ def _merge_entries(path, tree1, tree2):
             result.append((entry1, entry2))
             result.append((entry1, entry2))
             i1 += 1
             i1 += 1
             i2 += 1
             i2 += 1
-    for i in xrange(i1, len1):
+    for i in range(i1, len1):
         result.append((entries1[i], _NULL_ENTRY))
         result.append((entries1[i], _NULL_ENTRY))
-    for i in xrange(i2, len2):
+    for i in range(i2, len2):
         result.append((_NULL_ENTRY, entries2[i]))
         result.append((_NULL_ENTRY, entries2[i]))
     return result
     return result
 
 
@@ -265,7 +257,7 @@ def tree_changes_for_merge(store, parent_tree_ids, tree_id,
     change_type = lambda c: c.type
     change_type = lambda c: c.type
 
 
     # Yield only conflicting changes.
     # Yield only conflicting changes.
-    for _, changes in sorted(iteritems(changes_by_path)):
+    for _, changes in sorted(changes_by_path.items()):
         assert len(changes) == num_parents
         assert len(changes) == num_parents
         have = [c for c in changes if c is not None]
         have = [c for c in changes if c is not None]
         if _all_eq(have, change_type, CHANGE_DELETE):
         if _all_eq(have, change_type, CHANGE_DELETE):
@@ -330,7 +322,7 @@ def _common_bytes(blocks1, blocks2):
     if len(blocks1) > len(blocks2):
     if len(blocks1) > len(blocks2):
         blocks1, blocks2 = blocks2, blocks1
         blocks1, blocks2 = blocks2, blocks1
     score = 0
     score = 0
-    for block, count1 in iteritems(blocks1):
+    for block, count1 in blocks1.items():
         count2 = blocks2.get(block)
         count2 = blocks2.get(block)
         if count2:
         if count2:
             score += min(count1, count2)
             score += min(count1, count2)
@@ -458,9 +450,9 @@ class RenameDetector(object):
 
 
         add_paths = set()
         add_paths = set()
         delete_paths = set()
         delete_paths = set()
-        for sha, sha_deletes in iteritems(delete_map):
+        for sha, sha_deletes in delete_map.items():
             sha_adds = add_map[sha]
             sha_adds = add_map[sha]
-            for (old, is_delete), new in izip(sha_deletes, sha_adds):
+            for (old, is_delete), new in zip(sha_deletes, sha_adds):
                 if stat.S_IFMT(old.mode) != stat.S_IFMT(new.mode):
                 if stat.S_IFMT(old.mode) != stat.S_IFMT(new.mode):
                     continue
                     continue
                 if is_delete:
                 if is_delete:

+ 1 - 1
dulwich/greenthreads.py

@@ -132,7 +132,7 @@ class GreenThreadsObjectStoreIterator(ObjectStoreIterator):
             return len(self._shas)
             return len(self._shas)
         while len(self.finder.objects_to_send):
         while len(self.finder.objects_to_send):
             jobs = []
             jobs = []
-            for _ in xrange(0, len(self.finder.objects_to_send)):
+            for _ in range(0, len(self.finder.objects_to_send)):
                 jobs.append(self.p.spawn(self.finder.next))
                 jobs.append(self.p.spawn(self.finder.next))
             gevent.joinall(jobs)
             gevent.joinall(jobs)
             for j in jobs:
             for j in jobs:

+ 3 - 8
dulwich/index.py

@@ -39,11 +39,6 @@ from dulwich.pack import (
     SHA1Writer,
     SHA1Writer,
     )
     )
 
 
-if sys.version_info[0] == 2:
-    iteritems = lambda d: d.iteritems()
-else:
-    iteritems = lambda d: d.items()
-
 
 
 IndexEntry = collections.namedtuple(
 IndexEntry = collections.namedtuple(
     'IndexEntry', [
     'IndexEntry', [
@@ -279,10 +274,10 @@ class Index(object):
         del self._byname[name]
         del self._byname[name]
 
 
     def iteritems(self):
     def iteritems(self):
-        return iteritems(self._byname)
+        return self._byname.items()
 
 
     def update(self, entries):
     def update(self, entries):
-        for name, value in iteritems(entries):
+        for name, value in entries.items():
             self[name] = value
             self[name] = value
 
 
     def changes_from_tree(self, object_store, tree, want_unchanged=False):
     def changes_from_tree(self, object_store, tree, want_unchanged=False):
@@ -338,7 +333,7 @@ def commit_tree(object_store, blobs):
 
 
     def build_tree(path):
     def build_tree(path):
         tree = Tree()
         tree = Tree()
-        for basename, entry in iteritems(trees[path]):
+        for basename, entry in trees[path].items():
             if isinstance(entry, dict):
             if isinstance(entry, dict):
                 mode = stat.S_IFDIR
                 mode = stat.S_IFDIR
                 sha = build_tree(pathjoin(path, basename))
                 sha = build_tree(pathjoin(path, basename))

+ 1 - 5
dulwich/object_store.py

@@ -66,16 +66,12 @@ from dulwich.pack import (
 INFODIR = 'info'
 INFODIR = 'info'
 PACKDIR = 'pack'
 PACKDIR = 'pack'
 
 
-if sys.version_info[0] == 2:
-    iteritems = lambda d: d.iteritems()
-else:
-    iteritems = lambda d: d.items()
 
 
 class BaseObjectStore(object):
 class BaseObjectStore(object):
     """Object store interface."""
     """Object store interface."""
 
 
     def determine_wants_all(self, refs):
     def determine_wants_all(self, refs):
-        return [sha for (ref, sha) in iteritems(refs)
+        return [sha for (ref, sha) in refs.items()
                 if not sha in self and not ref.endswith(b"^{}") and
                 if not sha in self and not ref.endswith(b"^{}") and
                    not sha == ZERO_SHA]
                    not sha == ZERO_SHA]
 
 

+ 1 - 6
dulwich/objects.py

@@ -40,11 +40,6 @@ from dulwich.errors import (
     )
     )
 from dulwich.file import GitFile
 from dulwich.file import GitFile
 
 
-if sys.version_info[0] == 2:
-    iteritems = lambda d: d.iteritems()
-else:
-    iteritems = lambda d: d.items()
-
 
 
 ZERO_SHA = b'0' * 40
 ZERO_SHA = b'0' * 40
 
 
@@ -794,7 +789,7 @@ def sorted_tree_items(entries, name_order):
     :return: Iterator over (name, mode, hexsha)
     :return: Iterator over (name, mode, hexsha)
     """
     """
     key_func = name_order and key_entry_name_order or key_entry
     key_func = name_order and key_entry_name_order or key_entry
-    for name, entry in sorted(iteritems(entries), key=key_func):
+    for name, entry in sorted(entries.items(), key=key_func):
         mode, hexsha = entry
         mode, hexsha = entry
         # Stricter type checks than normal to mirror checks in the C version.
         # Stricter type checks than normal to mirror checks in the C version.
         mode = int(mode)
         mode = int(mode)

+ 6 - 11
dulwich/pack.py

@@ -85,11 +85,6 @@ from dulwich.objects import (
     object_header,
     object_header,
     )
     )
 
 
-if sys.version_info[0] == 2:
-    iteritems = lambda d: d.iteritems()
-else:
-    iteritems = lambda d: d.items()
-    xrange = range
 
 
 OFS_DELTA = 6
 OFS_DELTA = 6
 REF_DELTA = 7
 REF_DELTA = 7
@@ -782,7 +777,7 @@ class PackStreamReader(object):
         else:
         else:
             to_pop = max(n + tn - 20, 0)
             to_pop = max(n + tn - 20, 0)
             to_add = n
             to_add = n
-        self.sha.update(bytes(bytearray([self._trailer.popleft() for _ in xrange(to_pop)])))
+        self.sha.update(bytes(bytearray([self._trailer.popleft() for _ in range(to_pop)])))
         self._trailer.extend(data[-to_add:])
         self._trailer.extend(data[-to_add:])
 
 
         # hash everything but the trailer
         # hash everything but the trailer
@@ -845,7 +840,7 @@ class PackStreamReader(object):
         if pack_version is None:
         if pack_version is None:
             return
             return
 
 
-        for i in xrange(self._num_objects):
+        for i in range(self._num_objects):
             offset = self.offset
             offset = self.offset
             unpacked, unused = unpack_object(
             unpacked, unused = unpack_object(
               self.read, read_some=self.recv, compute_crc32=compute_crc32,
               self.read, read_some=self.recv, compute_crc32=compute_crc32,
@@ -1096,7 +1091,7 @@ class PackData(object):
 
 
     def iterobjects(self, progress=None, compute_crc32=True):
     def iterobjects(self, progress=None, compute_crc32=True):
         self._file.seek(self._header_size)
         self._file.seek(self._header_size)
-        for i in xrange(1, self._num_objects + 1):
+        for i in range(1, self._num_objects + 1):
             offset = self._file.tell()
             offset = self._file.tell()
             unpacked, unused = unpack_object(
             unpacked, unused = unpack_object(
               self._file.read, compute_crc32=compute_crc32)
               self._file.read, compute_crc32=compute_crc32)
@@ -1114,7 +1109,7 @@ class PackData(object):
         if self._num_objects is None:
         if self._num_objects is None:
             return
             return
 
 
-        for _ in xrange(self._num_objects):
+        for _ in range(self._num_objects):
             offset = self._file.tell()
             offset = self._file.tell()
             unpacked, unused = unpack_object(
             unpacked, unused = unpack_object(
               self._file.read, compute_crc32=False)
               self._file.read, compute_crc32=False)
@@ -1288,7 +1283,7 @@ class DeltaChainIterator(object):
             self._ensure_no_pending()
             self._ensure_no_pending()
             return
             return
 
 
-        for base_sha, pending in sorted(iteritems(self._pending_ref)):
+        for base_sha, pending in sorted(self._pending_ref.items()):
             if base_sha not in self._pending_ref:
             if base_sha not in self._pending_ref:
                 continue
                 continue
             try:
             try:
@@ -1482,7 +1477,7 @@ def write_pack(filename, objects, deltify=None, delta_window_size=None):
     with GitFile(filename + '.pack', 'wb') as f:
     with GitFile(filename + '.pack', 'wb') as f:
         entries, data_sum = write_pack_objects(f, objects,
         entries, data_sum = write_pack_objects(f, objects,
             delta_window_size=delta_window_size, deltify=deltify)
             delta_window_size=delta_window_size, deltify=deltify)
-    entries = [(k, v[0], v[1]) for (k, v) in iteritems(entries)]
+    entries = [(k, v[0], v[1]) for (k, v) in entries.items()]
     entries.sort()
     entries.sort()
     with GitFile(filename + '.idx', 'wb') as f:
     with GitFile(filename + '.idx', 'wb') as f:
         return data_sum, write_pack_index_v2(f, entries, data_sum)
         return data_sum, write_pack_index_v2(f, entries, data_sum)

+ 1 - 1
dulwich/tests/test_greenthreads.py

@@ -66,7 +66,7 @@ def create_commit(marker=None):
 
 
 def init_store(store, count=1):
 def init_store(store, count=1):
     ret = []
     ret = []
-    for i in xrange(0, count):
+    for i in range(0, count):
         objs = create_commit(marker=i)
         objs = create_commit(marker=i)
         for obj in objs:
         for obj in objs:
             ret.append(obj)
             ret.append(obj)