Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
xmr: bp - memory view optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Aug 17, 2018
1 parent b517906 commit 83ba7a6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/apps/monero/xmr/bulletproof.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class KeyV(object):
def __init__(self, elems=64, src=None, buffer=None):
self.current_idx = 0
self.d = None
self.mv = None
self.size = elems
if src:
self.d = bytearray(src.d)
Expand All @@ -283,14 +284,18 @@ def __init__(self, elems=64, src=None, buffer=None):
self.size = len(buffer) // 32
else:
self.d = bytearray(32 * elems)
self._set_mv()

def _set_mv(self):
self.mv = memoryview(self.d)

def __getitem__(self, item):
"""
Returns corresponding 32 byte array
:param item:
:return:
"""
return memoryview(self.d)[item * 32 : (item + 1) * 32]
return self.mv[item * 32 : (item + 1) * 32]

def __setitem__(self, key, value):
"""
Expand Down Expand Up @@ -326,10 +331,14 @@ def slice_r(self, start, stop):
res = KeyV(stop - start)
return self.slice(res, start, stop)

def copy_from(self, src):
self.size = self.size
self.d = bytearray(self.d)
self._set_mv()

def copy(self, dst=None):
if dst:
dst.size = self.size
dst.d = bytearray(self.d)
dst.copy_from(self)
else:
dst = KeyV(src=self)
return dst
Expand All @@ -342,6 +351,7 @@ def resize(self, nsize, chop=False):
else:
self.d = bytearray(nsize * 32)
self.size = nsize
self._set_mv()


class KeyVEval(KeyV):
Expand Down

0 comments on commit 83ba7a6

Please sign in to comment.