From f696a7933d1720f9c379597c16cfeb0c58db6d98 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sun, 30 Jul 2017 20:47:54 +0900 Subject: [PATCH] Prevent unnecessary copying of raw blocks --- lib/coins.py | 10 +++++----- lib/tx.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/coins.py b/lib/coins.py index af3d9af..9af5271 100644 --- a/lib/coins.py +++ b/lib/coins.py @@ -273,7 +273,7 @@ class Coin(object): def block(cls, raw_block, height): '''Return a Block namedtuple given a raw block and its height.''' header = cls.block_header(raw_block, height) - txs = cls.DESERIALIZER(raw_block[len(header):]).read_tx_block() + txs = cls.DESERIALIZER(raw_block, start=len(header)).read_tx_block() return Block(raw_block, header, txs) @classmethod @@ -313,8 +313,8 @@ class AuxPowMixin(object): @classmethod def block_header(cls, block, height): '''Return the AuxPow block header bytes''' - block = cls.DESERIALIZER(block) - return block.read_header(height, cls.BASIC_HEADER_SIZE) + deserializer = cls.DESERIALIZER(block) + return deserializer.read_header(height, cls.BASIC_HEADER_SIZE) class Bitcoin(Coin): @@ -762,8 +762,8 @@ class Zcash(Coin): @classmethod def block_header(cls, block, height): '''Return the block header bytes''' - block = cls.DESERIALIZER(block) - return block.read_header(height, cls.BASIC_HEADER_SIZE) + deserializer = cls.DESERIALIZER(block) + return deserializer.read_header(height, cls.BASIC_HEADER_SIZE) class Einsteinium(Coin): diff --git a/lib/tx.py b/lib/tx.py index 554f349..9151730 100644 --- a/lib/tx.py +++ b/lib/tx.py @@ -75,10 +75,10 @@ class Deserializer(object): millions of times during sync. ''' - def __init__(self, binary): + def __init__(self, binary, start=0): assert isinstance(binary, bytes) self.binary = binary - self.cursor = 0 + self.cursor = start def read_tx(self): '''Return a (Deserialized TX, TX_HASH) pair.