changeset 324:85612f32e9b6 trim

cythonise a bit
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Fri, 23 Jan 2026 15:52:59 +0000
parents dc7847750384
children 4c0508e54cca
files lib/python/cc/lmh/shrink.py
diffstat 1 files changed, 40 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/lib/python/cc/lmh/shrink.py	Fri Jan 23 15:50:15 2026 +0000
+++ b/lib/python/cc/lmh/shrink.py	Fri Jan 23 15:52:59 2026 +0000
@@ -5,35 +5,48 @@
 
    Usage: shrink.py infile.cdb_in cdate_prefix outfile.cdb_in
 '''
-import sys, io
+import sys, io, cython, types
 
 import shrink_key
 
-ifn = sys.argv.pop(1)
-dp = sys.argv.pop(1).encode('ascii')
-ofn = sys.argv.pop(1)
-dpl = len(dp)
-saved = 0
-#buf = io.BytesIO(bytearray(4))
+def mainp() -> None:
 
+  ifn = sys.argv.pop(1)
+  dp = sys.argv.pop(1).encode('ascii')
+  ofn = sys.argv.pop(1)
+  dpl: int = len(dp)
+  l: bytes
+  bb: bytes
+  od: bytes
+  oe: bytes
+  os1: bytes
+  os2: bytes
+  kl: int
+  ll: int
+  ol: bytes
+  nd: bytes
+  nlb: bytes
 
-with open(ifn,'rb') as f, open(ofn,'wb') as of:
-  for l in f:
-    if l == b'\n':
-      of.write(l)
-      break
-    (bb,od,oe) = l.rstrip().split(b':',2)
-    (os1,os2)=bb[1:].split(b',')
-    kl=int(os1)
-    ll=int(os2)
-    #print(od,dp,dpl,file=sys.stderr)
-    ol = oe[-ll:]
-    (nd,nlb)=shrink_key.shrink_date(od,dp,ol)
-    #print(i,od,nd,'%x'%nlb,file=sys.stderr)
-    of.write(b'+%d,%d'%(kl-(len(od)-len(nd)),len(nlb)))
-    of.write(b':')
-    of.write(nd)
-    of.write(b':')
-    of.write(oe[:-ll]) # includes the ->
-    of.write(nlb)
-    of.write(b'\n')
+  with open(ifn,'rb') as f, open(ofn,'wb') as of:
+    for l in f:
+      if l == b'\n':
+        of.write(l)
+        break
+      (bb,od,oe) = l.rstrip().split(b':',2)
+      (os1,os2)=bb[1:].split(b',')
+      kl=int(os1)
+      ll=int(os2)
+      #print(od,dp,dpl,file=sys.stderr)
+      ol = oe[-ll:]
+      (nd,nlb)=shrink_key.shrink_key(od,dp,ol)
+      #print(i,od,nd,'%x'%nlb,file=sys.stderr)
+      of.write(b'+%d,%d'%(kl-(len(od)-len(nd)),len(nlb)))
+      of.write(b':')
+      of.write(nd)
+      of.write(b':')
+      of.write(oe[:-ll]) # includes the ->
+      of.write(nlb)
+      of.write(b'\n')
+
+if __name__ == "__main__":
+    mainp()