From eb0263fb526dc9c32ac7aaf892c52ac7b46f27ae Mon Sep 17 00:00:00 2001 From: Anes Belfodil Date: Sat, 14 Nov 2020 18:47:23 -0500 Subject: [PATCH] Boost parsing performance --- backend/classification/parser/sd_file.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/classification/parser/sd_file.py b/backend/classification/parser/sd_file.py index f554d89d..4f93ac78 100644 --- a/backend/classification/parser/sd_file.py +++ b/backend/classification/parser/sd_file.py @@ -6,6 +6,9 @@ ROWS_TO_SKIP = 2 +SIGNED_BIT = int("800000", 16) +SIGNED_BIT_2 = 2 * SIGNED_BIT + def _hexstr_to_int(hexstr): """Converts a two complement hexadecimal value in a string to a signed float @@ -14,7 +17,8 @@ def _hexstr_to_int(hexstr): Returns: - decimal value """ - return int.from_bytes(bytes.fromhex(hexstr), byteorder='big', signed=True) + raw_int = int(hexstr, 16) + return raw_int - SIGNED_BIT_2 if raw_int >= SIGNED_BIT else raw_int def parse_sd_file(file):