[Zodb-checkins] CVS: StandaloneZODB/ZODB - utils.py:1.5

Jeremy Hylton jeremy@zope.com
Fri, 5 Oct 2001 16:06:14 -0400


Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv20364

Modified Files:
	utils.py 
Log Message:
Fix newTimeStamp() so it works when the first arg is not None.

Replace long multiplies with long shifts in U64() and u64().


=== StandaloneZODB/ZODB/utils.py 1.4 => 1.5 ===
 def p64(v, pack=struct.pack):
     """Pack an integer or long into a 8-byte string"""
-    if v < t32: h=0
+    if v < t32:
+        h = 0
     else:
-        h=v/t32
-        v=v%t32
+        h, v = divmod(v, t32)
     return pack(">II", h, v)
 
 def u64(v, unpack=struct.unpack):
     """Unpack an 8-byte string into a 64-bit (or long) integer"""
+    # XXX this seems to be just a slower version of U64()
     h, v = unpack(">ii", v)
-    if v < 0: v=t32+v
+    if v < 0:
+        v = t32 + v
     if h:
-        if h < 0: h=t32+h
-        v=h*t32+v
+        if h < 0:
+            h = t32 + h
+        v = (h << 32) + v
     return v
 
 def U64(v, unpack=struct.unpack):
     """Same as u64 but always returns a long."""
     h, v = unpack(">II", v)
     if h:
-        v=h*t32+v
+        v = (h << 32) + v
     return v
 
 def cp(f1, f2, l):
@@ -129,6 +132,7 @@
                  time=time.time, gmtime=time.gmtime):
     t=time()
     ts=TimeStamp(gmtime(t)[:5]+(t%60,))
-    if old is not None: return ts.laterThan(than)
+    if old is not None:
+        return ts.laterThan(old)