# HG changeset patch # User Henry S. Thompson # Date 1769183579 0 # Node ID 85612f32e9b6caa2d805ef18c75ce2b2353a534f # Parent dc784775038477e4de4b9a93f61675da8557beb3 cythonise a bit diff -r dc7847750384 -r 85612f32e9b6 lib/python/cc/lmh/shrink.py --- 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()