How would you approach optimizing a search algorithm?
Assume the input is a sorted array of integers. Implement binary search to return the index of target, or -1 if the target is absent. The function should avoid modifying the input and should handle an empty array.
Function: search_sorted(nums, target)
Input: A sorted integer array and an integer target.
Output: The target's index, or -1 when it is not present.
def search_sorted(nums, target):