Explorar el Código

Increase buffer sizes (#1637)

Jelmer Vernooij hace 1 mes
padre
commit
9240fc1992
Se han modificado 3 ficheros con 13 adiciones y 5 borrados
  1. 11 3
      dulwich/line_ending.py
  2. 1 1
      dulwich/pack.py
  3. 1 1
      dulwich/protocol.py

+ 11 - 3
dulwich/line_ending.py

@@ -168,9 +168,17 @@ def convert_lf_to_crlf(text_hunk: bytes) -> bytes:
       text_hunk: A bytes string representing a text hunk
     Returns: The text hunk with the same type, with LF replaced into CRLF
     """
-    # TODO find a more efficient way of doing it
-    intermediary = text_hunk.replace(CRLF, LF)
-    return intermediary.replace(LF, CRLF)
+    # Single-pass conversion: split on LF and join with CRLF
+    # This avoids the double replacement issue
+    parts = text_hunk.split(LF)
+    # Remove any trailing CR to avoid CRCRLF
+    cleaned_parts = []
+    for i, part in enumerate(parts):
+        if i < len(parts) - 1 and part.endswith(b"\r"):
+            cleaned_parts.append(part[:-1])
+        else:
+            cleaned_parts.append(part)
+    return CRLF.join(cleaned_parts)
 
 
 def get_checkout_filter(

+ 1 - 1
dulwich/pack.py

@@ -282,7 +282,7 @@ class UnpackedObject:
         return "{}({})".format(self.__class__.__name__, ", ".join(data))
 
 
-_ZLIB_BUFSIZE = 4096
+_ZLIB_BUFSIZE = 65536  # 64KB buffer for better I/O performance
 
 
 def read_zlib_chunks(

+ 1 - 1
dulwich/protocol.py

@@ -382,7 +382,7 @@ class Protocol:
         return parse_cmd_pkt(line)
 
 
-_RBUFSIZE = 8192  # Default read buffer size.
+_RBUFSIZE = 65536  # 64KB buffer for better network I/O performance
 
 
 class ReceivableProtocol(Protocol):