Rev 10: Get rid of all the special-casing code. in http://bzr.arbash-meinel.com/plugins/index2

John Arbash Meinel john at arbash-meinel.com
Tue Jul 1 19:43:05 BST 2008


At http://bzr.arbash-meinel.com/plugins/index2

------------------------------------------------------------
revno: 10
revision-id: john at arbash-meinel.com-20080701184228-dhck7vdmkh47zspa
parent: john at arbash-meinel.com-20080701183855-ynb3lm34yrq6sp3w
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: index2
timestamp: Tue 2008-07-01 13:42:28 -0500
message:
  Get rid of all the special-casing code.
  
  It didn't really help much, because we are going to do a repack anyway.
  And it really simplifies the code.
-------------- next part --------------
=== modified file 'chunk_writer.py'
--- a/chunk_writer.py	2008-07-01 18:38:55 +0000
+++ b/chunk_writer.py	2008-07-01 18:42:28 +0000
@@ -40,7 +40,6 @@
         self.bytes_in = []
         self.bytes_list = []
         self.compressed = None
-        self.seen_bytes = 0
         self.unused_bytes = None
 
     def finish(self):
@@ -79,47 +78,37 @@
         If the bytes fit, False is returned. Otherwise True is returned
         and the bytes have not been added to the chunk.
         """
-        # Check quickly to see if this is likely to put us outside of our
-        # budget:
-        next_seen_size = self.seen_bytes + len(bytes)
-        if (next_seen_size < self.chunk_size):
-            # No need, we assume this will "just fit"
-            out = self.compressor.compress(bytes)
-            self.bytes_in.append(bytes)
-            self.seen_bytes = next_seen_size
-            if out:
-                self.bytes_list.append(out)
-        else:
-            # This may or may not fit, try to add it with Z_SYNC_FLUSH
-            out = self.compressor.compress(bytes)
-            if out:
-                self.bytes_list.append(out)
-            out = self.compressor.flush(Z_SYNC_FLUSH)
-            if out:
-                self.bytes_list.append(out)
-            total_len = sum(len(b) for b in self.bytes_list)
-            # Give us some extra room for a final Z_FINISH call.
-            if total_len + 10 > self.chunk_size:
-                # We are over budget, try to squeeze this in without any
-                # Z_SYNC_FLUSH calls
-                bytes_out, compressor = self._recompress_all_bytes_in(bytes)
-                this_len = sum(len(b) for b in bytes_out)
-                if this_len + 10 > self.chunk_size:
-                    # No way we can add anymore, we need to re-pack because our
-                    # compressor is now out of sync
-                    bytes_out, compressor = self._recompress_all_bytes_in()
-                    self.compressor = compressor
-                    self.bytes_list = bytes_out
-                    self.unused_bytes = bytes
-                    return True
-                else:
-                    # This fits when we pack it tighter, so use the new packing
-                    self.compressor = compressor
-                    self.bytes_in.append(bytes)
-                    self.bytes_list = bytes_out
+        # Add these bytes using Z_SYNC_FLUSH, if it puts us over budget, we
+        # will try packing everything tighter, if that still fails, then we
+        # will reject this request.
+        out = self.compressor.compress(bytes)
+        if out:
+            self.bytes_list.append(out)
+        out = self.compressor.flush(Z_SYNC_FLUSH)
+        if out:
+            self.bytes_list.append(out)
+        total_len = sum(len(b) for b in self.bytes_list)
+        # Give us some extra room for a final Z_FINISH call.
+        if total_len + 10 > self.chunk_size:
+            # We are over budget, try to squeeze this in without any
+            # Z_SYNC_FLUSH calls
+            bytes_out, compressor = self._recompress_all_bytes_in(bytes)
+            this_len = sum(len(b) for b in bytes_out)
+            if this_len + 10 > self.chunk_size:
+                # No way we can add anymore, we need to re-pack because our
+                # compressor is now out of sync
+                bytes_out, compressor = self._recompress_all_bytes_in()
+                self.compressor = compressor
+                self.bytes_list = bytes_out
+                self.unused_bytes = bytes
+                return True
             else:
-                # It fit, so mark it added
+                # This fits when we pack it tighter, so use the new packing
+                self.compressor = compressor
                 self.bytes_in.append(bytes)
-                self.seen_bytes = next_seen_size
+                self.bytes_list = bytes_out
+        else:
+            # It fit, so mark it added
+            self.bytes_in.append(bytes)
         return False
 



More information about the bazaar-commits mailing list