]> arthur.barton.de Git - bup.git/commit - lib/bup/_helpers.c
vint: implement encoding in C
authorJohannes Berg <johannes@sipsolutions.net>
Fri, 31 Jan 2020 22:27:14 +0000 (23:27 +0100)
committerRob Browning <rlb@defaultvalue.org>
Sat, 15 May 2021 18:56:36 +0000 (13:56 -0500)
commitfcb11e0fd5df5ee606df6404bb1f9ce8dc41baab
treea7a3e27b19e619adc93763fd34295c9959ef35b2
parent9244bf9e0a856c1d7cdd657a3bf5c0e29644c621
vint: implement encoding in C

The vuint/vint encoding is quite slow, possibly due to the use
of BytesIO and byte-wise writing, for what's really almost always
a fixed-size buffer since we typically don't deal with values
that don't fit into a 64-bit signed integer.

Implement this in C to make it faster, at least for those that
fit into signed 64-bit integers (long long, because python makes
overflow checking for unsigned 64-bit integers hard), and if the
C version throws an OverflowError, fall back to the python code.

Also add a test for something that doesn't actually fit into a
64-bit integer.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
[rlb@defaultvalue.org: adjusted bup_vuint_encode and bup_vint_encode
 to just directly return the PyBytes_FromStringAndSize result]
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/_helpers.c
lib/bup/vint.py
test/int/test_vint.py