Skip to content

Commit cfdf283

Browse files
authored
perf: python get_object_value_from_key_list (10%) (ccxt#27779)
perf: python get_object_value_from_key_list 10%-15%
1 parent 7af9bad commit cfdf283

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

python/ccxt/base/exchange.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -913,15 +913,19 @@ def safe_value_n(dictionary, key_list, default_value=None):
913913

914914
@staticmethod
915915
def get_object_value_from_key_list(dictionary_or_list, key_list):
916-
isDataArray = isinstance(dictionary_or_list, list)
917-
isDataDict = isinstance(dictionary_or_list, dict)
918-
for key in key_list:
919-
if isDataDict:
920-
if key in dictionary_or_list and dictionary_or_list[key] is not None and dictionary_or_list[key] != '':
921-
return dictionary_or_list[key]
922-
elif isDataArray and not isinstance(key, str):
923-
if (key < len(dictionary_or_list)) and (dictionary_or_list[key] is not None) and (dictionary_or_list[key] != ''):
924-
return dictionary_or_list[key]
916+
if isinstance(dictionary_or_list, dict):
917+
get = dictionary_or_list.get
918+
for key in key_list:
919+
value = get(key)
920+
if value is not None and value != '':
921+
return value
922+
elif isinstance(dictionary_or_list, list):
923+
length = len(dictionary_or_list)
924+
for key in key_list:
925+
if isinstance(key, int) and 0 <= key < length:
926+
value = dictionary_or_list[key]
927+
if value is not None and value != '':
928+
return value
925929
return None
926930

927931
@staticmethod

0 commit comments

Comments
 (0)