summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmon <Harmon758@gmail.com>2020-02-16 07:36:03 -0600
committerHarmon <Harmon758@gmail.com>2020-02-16 07:36:03 -0600
commit3d14cc84b0a5e42d755d24d77a6e4af6bea8c3c1 (patch)
tree052a2b73751eb8cf48adb0a029757eb41ad106a8
parent4a692fdd43e67810509b1c1843fa203714b14f0e (diff)
downloadgitdb-3d14cc84b0a5e42d755d24d77a6e4af6bea8c3c1.tar.gz
Remove and replace compat.buffer
-rw-r--r--gitdb/fun.py8
-rw-r--r--gitdb/pack.py11
-rw-r--r--gitdb/stream.py5
-rw-r--r--gitdb/utils/compat.py10
4 files changed, 10 insertions, 24 deletions
diff --git a/gitdb/fun.py b/gitdb/fun.py
index 7203de9..92b8b1c 100644
--- a/gitdb/fun.py
+++ b/gitdb/fun.py
@@ -16,7 +16,7 @@ from functools import reduce
from gitdb.const import NULL_BYTE, BYTE_SPACE
from gitdb.utils.encoding import force_text
-from gitdb.utils.compat import buffer, PY3
+from gitdb.utils.compat import PY3
from gitdb.typ import (
str_blob_type,
str_commit_type,
@@ -101,7 +101,7 @@ def delta_chunk_apply(dc, bbuf, write):
:param write: write method to call with data to write"""
if dc.data is None:
# COPY DATA FROM SOURCE
- write(buffer(bbuf, dc.so, dc.ts))
+ write(bbuf[dc.so:dc.so + dc.ts])
else:
# APPEND DATA
# 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):
if (rbound < cp_size or
rbound > src_buf_size):
break
- write(buffer(src_buf, cp_off, cp_size))
+ write(src_buf[cp_off:cp_off + cp_size])
elif c:
write(db[i:i + c])
i += c
@@ -741,7 +741,7 @@ def apply_delta_data(src_buf, src_buf_size, delta_buf, delta_buf_size, write):
if (rbound < cp_size or
rbound > src_buf_size):
break
- write(buffer(src_buf, cp_off, cp_size))
+ write(src_buf[cp_off:cp_off + cp_size])
elif c:
write(db[i:i + c])
i += c
diff --git a/gitdb/pack.py b/gitdb/pack.py
index f010554..68da2b7 100644
--- a/gitdb/pack.py
+++ b/gitdb/pack.py
@@ -62,10 +62,7 @@ from struct import pack
from binascii import crc32
from gitdb.const import NULL_BYTE
-from gitdb.utils.compat import (
- buffer,
- to_bytes
-)
+from gitdb.utils.compat import to_bytes
import tempfile
import array
@@ -117,7 +114,7 @@ def pack_object_at(cursor, offset, as_stream):
# END handle type id
abs_data_offset = offset + total_rela_offset
if as_stream:
- stream = DecompressMemMapReader(buffer(data, total_rela_offset), False, uncomp_size)
+ stream = DecompressMemMapReader(data[total_rela_offset:], False, uncomp_size)
if delta_info is None:
return abs_data_offset, OPackStream(offset, type_id, uncomp_size, stream)
else:
@@ -408,7 +405,7 @@ class PackIndexFile(LazyMixin):
if self._version == 2:
# read stream to array, convert to tuple
a = array.array('I') # 4 byte unsigned int, long are 8 byte on 64 bit it appears
- a.frombytes(buffer(self._cursor.map(), self._pack_offset, self._pack_64_offset - self._pack_offset))
+ a.frombytes(self._cursor.map()[self._pack_offset:self._pack_64_offset])
# networkbyteorder to something array likes more
if sys.byteorder == 'little':
@@ -836,7 +833,7 @@ class PackEntity(LazyMixin):
while cur_pos < next_offset:
rbound = min(cur_pos + chunk_size, next_offset)
size = rbound - cur_pos
- this_crc_value = crc_update(buffer(pack_data, cur_pos, size), this_crc_value)
+ this_crc_value = crc_update(pack_data[cur_pos:cur_pos + size], this_crc_value)
cur_pos += size
# END window size loop
diff --git a/gitdb/stream.py b/gitdb/stream.py
index 2f4c12d..b94ef24 100644
--- a/gitdb/stream.py
+++ b/gitdb/stream.py
@@ -27,7 +27,6 @@ from gitdb.util import (
)
from gitdb.const import NULL_BYTE, BYTE_SPACE
-from gitdb.utils.compat import buffer
from gitdb.utils.encoding import force_bytes
has_perf_mod = False
@@ -278,7 +277,7 @@ class DecompressMemMapReader(LazyMixin):
# END adjust winsize
# takes a slice, but doesn't copy the data, it says ...
- indata = buffer(self._m, self._cws, self._cwe - self._cws)
+ indata = self._m[self._cws:self._cwe]
# get the actual window end to be sure we don't use it for computations
self._cwe = self._cws + len(indata)
@@ -414,7 +413,7 @@ class DeltaApplyReader(LazyMixin):
buf = dstream.read(512) # read the header information + X
offset, src_size = msb_size(buf)
offset, target_size = msb_size(buf, offset)
- buffer_info_list.append((buffer(buf, offset), offset, src_size, target_size))
+ buffer_info_list.append((buf[offset:], offset, src_size, target_size))
max_target_size = max(max_target_size, target_size)
# END for each delta stream
diff --git a/gitdb/utils/compat.py b/gitdb/utils/compat.py
index 99e7ae6..8c7c06b 100644
--- a/gitdb/utils/compat.py
+++ b/gitdb/utils/compat.py
@@ -4,22 +4,12 @@ PY3 = sys.version_info[0] == 3
try:
# Python 2
- buffer = buffer
memoryview = buffer
# Assume no memory view ...
def to_bytes(i):
return i
except NameError:
# Python 3 has no `buffer`; only `memoryview`
- # However, it's faster to just slice the object directly, maybe it keeps a view internally
- def buffer(obj, offset, size=None):
- if size is None:
- # return memoryview(obj)[offset:]
- return obj[offset:]
- else:
- # return memoryview(obj)[offset:offset+size]
- return obj[offset:offset + size]
- # end buffer reimplementation
# smmap can return memory view objects, which can't be compared as buffers/bytes can ...
def to_bytes(i):
if isinstance(i, memoryview):