Skip to content

Commit 8cd9d62

Browse files
committed
Remove extra map lookup from very hot code
This provides a small performance improvement.
1 parent 17a155b commit 8cd9d62

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

maxminddb/decoder.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ def decode(self, offset):
125125
if not type_num:
126126
(type_num, new_offset) = self._read_extended(new_offset)
127127

128-
if type_num not in self._type_decoder:
128+
try:
129+
decoder = self._type_decoder[type_num]
130+
except KeyError:
129131
raise InvalidDatabaseError('Unexpected type number ({type}) '
130132
'encountered'.format(type=type_num))
131133

132134
(size, new_offset) = self._size_from_ctrl_byte(ctrl_byte, new_offset,
133135
type_num)
134-
return self._type_decoder[type_num](self, size, new_offset)
136+
return decoder(self, size, new_offset)
135137

136138
def _read_extended(self, offset):
137139
(next_byte, ) = struct.unpack(b'!B', self._buffer[offset:offset + 1])

0 commit comments

Comments
 (0)