Commit b50f8e3a authored by Jeremy Hylton's avatar Jeremy Hylton

Make classes with __slots__ into new-style objects.

Move two class variable definitions into __init__(), because class
variables defined in __slots__ are immutable.  This should still be a
net memory savings, because the a 8-entry dict and a 10-entry dict
both have the same allocated size.
parent 2377736c
...@@ -195,7 +195,7 @@ class FileStorageFormatter: ...@@ -195,7 +195,7 @@ class FileStorageFormatter:
def DataHeaderFromString(s): def DataHeaderFromString(s):
return DataHeader(*struct.unpack(DATA_HDR, s)) return DataHeader(*struct.unpack(DATA_HDR, s))
class DataHeader: class DataHeader(object):
"""Header for a data record.""" """Header for a data record."""
__slots__ = ( __slots__ = (
...@@ -203,10 +203,9 @@ class DataHeader: ...@@ -203,10 +203,9 @@ class DataHeader:
# These three attributes are only defined when vlen > 0 # These three attributes are only defined when vlen > 0
"pnv", "vprev", "version") "pnv", "vprev", "version")
version = ""
back = 0
def __init__(self, oid, serial, prev, tloc, vlen, plen): def __init__(self, oid, serial, prev, tloc, vlen, plen):
self.back = 0 # default
self.version = "" # default
self.oid = oid self.oid = oid
self.serial = serial self.serial = serial
if isinstance(prev, StringType): if isinstance(prev, StringType):
...@@ -251,7 +250,7 @@ class DataHeader: ...@@ -251,7 +250,7 @@ class DataHeader:
def TxnHeaderFromString(s): def TxnHeaderFromString(s):
return TxnHeader(*struct.unpack(TRANS_HDR, s)) return TxnHeader(*struct.unpack(TRANS_HDR, s))
class TxnHeader: class TxnHeader(object):
"""Header for a transaction record.""" """Header for a transaction record."""
__slots__ = ("tid", "tlen", "status", "user", "descr", "ext", __slots__ = ("tid", "tlen", "status", "user", "descr", "ext",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment