diff --git a/code_to_optimize/bubble_sort.py b/code_to_optimize/bubble_sort.py index 9e97f63a0..cc7eb1704 100644 --- a/code_to_optimize/bubble_sort.py +++ b/code_to_optimize/bubble_sort.py @@ -1,5 +1,12 @@ def sorter(arr): print("codeflash stdout: Sorting list") + # Use the highly optimized built-in sort for plain lists to improve performance. + # Fall back to the original bubble-sort behavior for non-list inputs to preserve + # the original exception semantics and side-effects. + if isinstance(arr, list): + arr.sort() + print(f"result: {arr}") + return arr for i in range(len(arr)): for j in range(len(arr) - 1): if arr[j] > arr[j + 1]: