Skip to content

Commit 33e01ee

Browse files
authored
Boost parsing performance (#84)
1 parent fd04292 commit 33e01ee

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

backend/classification/parser/sd_file.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
ROWS_TO_SKIP = 2
88

9+
SIGNED_BIT = int("800000", 16)
10+
SIGNED_BIT_2 = 2 * SIGNED_BIT
11+
912

1013
def _hexstr_to_int(hexstr):
1114
"""Converts a two complement hexadecimal value in a string to a signed float
@@ -14,7 +17,8 @@ def _hexstr_to_int(hexstr):
1417
Returns:
1518
- decimal value
1619
"""
17-
return int.from_bytes(bytes.fromhex(hexstr), byteorder='big', signed=True)
20+
raw_int = int(hexstr, 16)
21+
return raw_int - SIGNED_BIT_2 if raw_int >= SIGNED_BIT else raw_int
1822

1923

2024
def parse_sd_file(file):

0 commit comments

Comments
 (0)