comparison roundup/rest.py @ 8542:a4f017ae1477

perf: dereference methods before using in loop I have a few comprehensions where I use self.FsValue and self.json_dict. Assign self.X to a variable and use the variable in the comprehension. This may provide a little speedup since the lookup is done once.
author John Rouillard <rouilj@ieee.org>
date Tue, 24 Mar 2026 16:56:38 -0400
parents 5800afdebded
children 1ffa1f42e1da
comparison
equal deleted inserted replaced
8541:7a7f6ee0a09e 8542:a4f017ae1477
2759 if json_string == "": 2759 if json_string == "":
2760 self.json_dict = {} 2760 self.json_dict = {}
2761 self.value = None 2761 self.value = None
2762 return 2762 return
2763 2763
2764 fsvalue = self.FsValue
2764 try: 2765 try:
2765 self.json_dict = json.loads(json_string, 2766 self.json_dict = json.loads(json_string,
2766 parse_constant=raise_error_on_constant) 2767 parse_constant=raise_error_on_constant)
2767 self.value = [self.FsValue(index, self.json_dict[index]) 2768 json_dict = self.json_dict
2768 for index in self.json_dict if 2769 self.value = [fsvalue(index, json_dict[index])
2769 self.json_dict[index] is not None] 2770 for index in json_dict if
2771 json_dict[index] is not None]
2770 except (JSONDecodeError, ValueError) as e: 2772 except (JSONDecodeError, ValueError) as e:
2771 raise ValueError(e.args[0] + ". JSON is: " + json_string) 2773 raise ValueError(e.args[0] + ". JSON is: " + json_string)
2772 2774
2773 class FsValue: 2775 class FsValue:
2774 2776

Roundup Issue Tracker: http://roundup-tracker.org/