[Zodb-checkins] CVS: StandaloneZODB/ZEO - ClientCache.py:1.14.4.7
Jeremy Hylton
jeremy@zope.com
Fri, 4 Jan 2002 17:20:33 -0500
Update of /cvs-repository/StandaloneZODB/ZEO
In directory cvs.zope.org:/tmp/cvs-serv13936
Modified Files:
Tag: ZEO-ZRPC-Dev
ClientCache.py
Log Message:
Reformat and refactor store() implementation.
Reformat based on guidelines from the Society for the Promotion of
Whitespace.
Accumulate individual strings to write in a list and do a single join
and write at the end. Replaces several string + ops and several write
calls.
Undo use of temporary variables to avoid attribute lookups.
=== StandaloneZODB/ZEO/ClientCache.py 1.14.4.6 => 1.14.4.7 ===
def store(self, oid, p, s, version, pv, sv):
self._acquire()
- try: self._store(oid, p, s, version, pv, sv)
- finally: self._release()
+ try:
+ self._store(oid, p, s, version, pv, sv)
+ finally:
+ self._release()
def _store(self, oid, p, s, version, pv, sv):
if not s:
- p=''
- s='\0\0\0\0\0\0\0\0'
- tlen=31+len(p)
+ p = ''
+ s = '\0\0\0\0\0\0\0\0'
+ tlen = 31 + len(p)
if version:
- tlen=tlen+len(version)+12+len(pv)
- vlen=len(version)
+ tlen = tlen + len(version) + 12 + len(pv)
+ vlen = len(version)
else:
- vlen=0
+ vlen = 0
- pos=self._pos
- current=self._current
- f=self._f[current]
- f.seek(pos)
- stlen=pack(">I",tlen)
- write=f.write
- write(oid+'v'+stlen+pack(">HI", vlen, len(p))+s)
- if p: write(p)
+ stlen = pack(">I", tlen)
+ # accumulate various data to write into a list
+ l = [oid, 'v', stlen, pack(">HI", vlen, len(p)), s]
+ if p:
+ l.append(p)
if version:
- write(version)
- write(pack(">I", len(pv)))
- write(pv)
- write(sv)
+ l.extend([version,
+ pack(">I", len(pv)),
+ pv, sv])
+ l.append(stlen)
+ f = self._f[self._current]
+ f.seek(self._pos)
+ f.write("".join(l))
- write(stlen)
-
- if current: self._index[oid]=-pos
- else: self._index[oid]=pos
+ if self._current:
+ self._index[oid] = - self._pos
+ else:
+ self._index[oid] = self._pos
- self._pos=pos+tlen
+ self._pos += tlen
def read_index(index, serial, f, current):
seek=f.seek