Skip to content

Commit 3d14cc8

Browse files
committed
Remove and replace compat.buffer
1 parent 4a692fd commit 3d14cc8

File tree

4 files changed

+10
-24
lines changed

4 files changed

+10
-24
lines changed

gitdb/fun.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from gitdb.const import NULL_BYTE, BYTE_SPACE
1818
from gitdb.utils.encoding import force_text
19-
from gitdb.utils.compat import buffer, PY3
19+
from gitdb.utils.compat import PY3
2020
from gitdb.typ import (
2121
str_blob_type,
2222
str_commit_type,
@@ -101,7 +101,7 @@ def delta_chunk_apply(dc, bbuf, write):
101101
:param write: write method to call with data to write"""
102102
if dc.data is None:
103103
# COPY DATA FROM SOURCE
104-
write(buffer(bbuf, dc.so, dc.ts))
104+
write(bbuf[dc.so:dc.so + dc.ts])
105105
else:
106106
# APPEND DATA
107107
# whats faster: if + 4 function calls or just a write with a slice ?
@@ -698,7 +698,7 @@ def apply_delta_data(src_buf, src_buf_size, delta_buf, delta_buf_size, write):
698698
if (rbound < cp_size or
699699
rbound > src_buf_size):
700700
break
701-
write(buffer(src_buf, cp_off, cp_size))
701+
write(src_buf[cp_off:cp_off + cp_size])
702702
elif c:
703703
write(db[i:i + c])
704704
i += c
@@ -741,7 +741,7 @@ def apply_delta_data(src_buf, src_buf_size, delta_buf, delta_buf_size, write):
741741
if (rbound < cp_size or
742742
rbound > src_buf_size):
743743
break
744-
write(buffer(src_buf, cp_off, cp_size))
744+
write(src_buf[cp_off:cp_off + cp_size])
745745
elif c:
746746
write(db[i:i + c])
747747
i += c

gitdb/pack.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@
6262
from binascii import crc32
6363

6464
from gitdb.const import NULL_BYTE
65-
from gitdb.utils.compat import (
66-
buffer,
67-
to_bytes
68-
)
65+
from gitdb.utils.compat import to_bytes
6966

7067
import tempfile
7168
import array
@@ -117,7 +114,7 @@ def pack_object_at(cursor, offset, as_stream):
117114
# END handle type id
118115
abs_data_offset = offset + total_rela_offset
119116
if as_stream:
120-
stream = DecompressMemMapReader(buffer(data, total_rela_offset), False, uncomp_size)
117+
stream = DecompressMemMapReader(data[total_rela_offset:], False, uncomp_size)
121118
if delta_info is None:
122119
return abs_data_offset, OPackStream(offset, type_id, uncomp_size, stream)
123120
else:
@@ -408,7 +405,7 @@ def offsets(self):
408405
if self._version == 2:
409406
# read stream to array, convert to tuple
410407
a = array.array('I') # 4 byte unsigned int, long are 8 byte on 64 bit it appears
411-
a.frombytes(buffer(self._cursor.map(), self._pack_offset, self._pack_64_offset - self._pack_offset))
408+
a.frombytes(self._cursor.map()[self._pack_offset:self._pack_64_offset])
412409

413410
# networkbyteorder to something array likes more
414411
if sys.byteorder == 'little':
@@ -836,7 +833,7 @@ def is_valid_stream(self, sha, use_crc=False):
836833
while cur_pos < next_offset:
837834
rbound = min(cur_pos + chunk_size, next_offset)
838835
size = rbound - cur_pos
839-
this_crc_value = crc_update(buffer(pack_data, cur_pos, size), this_crc_value)
836+
this_crc_value = crc_update(pack_data[cur_pos:cur_pos + size], this_crc_value)
840837
cur_pos += size
841838
# END window size loop
842839

gitdb/stream.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
)
2828

2929
from gitdb.const import NULL_BYTE, BYTE_SPACE
30-
from gitdb.utils.compat import buffer
3130
from gitdb.utils.encoding import force_bytes
3231

3332
has_perf_mod = False
@@ -278,7 +277,7 @@ def read(self, size=-1):
278277
# END adjust winsize
279278

280279
# takes a slice, but doesn't copy the data, it says ...
281-
indata = buffer(self._m, self._cws, self._cwe - self._cws)
280+
indata = self._m[self._cws:self._cwe]
282281

283282
# get the actual window end to be sure we don't use it for computations
284283
self._cwe = self._cws + len(indata)
@@ -414,7 +413,7 @@ def _set_cache_brute_(self, attr):
414413
buf = dstream.read(512) # read the header information + X
415414
offset, src_size = msb_size(buf)
416415
offset, target_size = msb_size(buf, offset)
417-
buffer_info_list.append((buffer(buf, offset), offset, src_size, target_size))
416+
buffer_info_list.append((buf[offset:], offset, src_size, target_size))
418417
max_target_size = max(max_target_size, target_size)
419418
# END for each delta stream
420419

gitdb/utils/compat.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,12 @@
44

55
try:
66
# Python 2
7-
buffer = buffer
87
memoryview = buffer
98
# Assume no memory view ...
109
def to_bytes(i):
1110
return i
1211
except NameError:
1312
# Python 3 has no `buffer`; only `memoryview`
14-
# However, it's faster to just slice the object directly, maybe it keeps a view internally
15-
def buffer(obj, offset, size=None):
16-
if size is None:
17-
# return memoryview(obj)[offset:]
18-
return obj[offset:]
19-
else:
20-
# return memoryview(obj)[offset:offset+size]
21-
return obj[offset:offset + size]
22-
# end buffer reimplementation
2313
# smmap can return memory view objects, which can't be compared as buffers/bytes can ...
2414
def to_bytes(i):
2515
if isinstance(i, memoryview):

0 commit comments

Comments
 (0)