Skip to content

Commit 757370d

Browse files
authored
Faster Message string representation (#1858)
Improved the speed of data conversion to hex string
1 parent 7302127 commit 757370d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

can/message.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,11 @@ def __str__(self) -> str:
130130
field_strings.append(flag_string)
131131

132132
field_strings.append(f"DL: {self.dlc:2d}")
133-
data_strings = []
133+
data_strings = ""
134134
if self.data is not None:
135-
for index in range(0, min(self.dlc, len(self.data))):
136-
data_strings.append(f"{self.data[index]:02x}")
135+
data_strings = self.data[: min(self.dlc, len(self.data))].hex(" ")
137136
if data_strings: # if not empty
138-
field_strings.append(" ".join(data_strings).ljust(24, " "))
137+
field_strings.append(data_strings.ljust(24, " "))
139138
else:
140139
field_strings.append(" " * 24)
141140

0 commit comments

Comments
 (0)