~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/dirstate.py

610ms: Optimizing _entries_to_current state brings the 'slow path' down to 610 ms (inlined and uglier fast path is 570-580ms)

Show diffs side-by-side

added added

removed removed

Lines of Context:
403
403
        current_block = self._dirblocks[0][1]
404
404
        current_dirname = ''
405
405
        root_key = ('', '')
 
406
        append_entry = current_block.append
406
407
        for entry in new_entries:
407
408
            if entry[0][0] != current_dirname:
408
409
                # new block - different dirname
409
410
                current_block = []
410
411
                current_dirname = entry[0][0]
411
412
                self._dirblocks.append((current_dirname, current_block))
412
 
            elif entry[0][1]:
413
 
                # this is not a root entry for a tree (it has a basename)
414
 
                current_block = self._dirblocks[-1][1]
 
413
                append_entry = current_block.append
415
414
            # append the entry to the current block
416
 
            current_block.append(entry)
417
 
    
 
415
            append_entry(entry)
 
416
        self._split_root_dirblock_into_contents()
 
417
 
 
418
    def _split_root_dirblock_into_contents(self):
 
419
        """Split the root dirblocks into root and contents-of-root.
 
420
 
 
421
        After parsing by path, we end up with root entries and contents-of-root
 
422
        entries in the same block. This loop splits them out again.
 
423
        """
 
424
        # The above loop leaves the "root block" entries mixed with the
 
425
        # "contents-of-root block". But we don't want an if check on
 
426
        # all entries, so instead we just fix it up here.
 
427
        assert self._dirblocks[1] == ('', [])
 
428
        root_block = []
 
429
        contents_of_root_block = []
 
430
        for entry in self._dirblocks[0][1]:
 
431
            if not entry[0][1]: # This is a root entry
 
432
                root_block.append(entry)
 
433
            else:
 
434
                contents_of_root_block.append(entry)
 
435
        self._dirblocks[0] = ('', root_block)
 
436
        self._dirblocks[1] = ('', contents_of_root_block)
 
437
 
418
438
    def _entry_to_line(self, entry):
419
439
        """Serialize entry to a NULL delimited line ready for _get_output_lines.
420
440
        
920
940
                    assert trailing == '\n'
921
941
                    # append the entry to the current block
922
942
                    append_entry(entry)
923
 
                # The above loop leaves the "root block" entries mixed with the
924
 
                # "contents-of-root block". But we don't want an if check on
925
 
                # all entries, so instead we just fix it up here.
926
 
                assert self._dirblocks[1] == ('', [])
927
 
                root_block = []
928
 
                contents_of_root_block = []
929
 
                for entry in self._dirblocks[0][1]:
930
 
                    if not entry[0][1]: # This is a root entry
931
 
                        root_block.append(entry)
932
 
                    else:
933
 
                        contents_of_root_block.append(entry)
934
 
                self._dirblocks[0] = ('', root_block)
935
 
                self._dirblocks[1] = ('', contents_of_root_block)
 
943
                self._split_root_dirblock_into_contents()
936
944
            else:
937
945
                fields_to_entry = self._get_fields_to_entry()
938
946
                entries = [fields_to_entry(fields[pos:pos+entry_size])