You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In func Sort(data Interface), we already call data.Len(). However we don't check to see if it returned a value < 2. We should, and if so, return immediately. As it is now, without this simple check, we end up allocating memory, regardless of whether or not we can do anything with the item passed.
Adding this check should have an insignificant impact on other calls to this function, since we're just doing a simple test on a variable we already have.
The text was updated successfully, but these errors were encountered:
It doesn't look like it ends up allocating any memory or doing any work, at least at tip.
Sort calls quickSort which checks if it has over 7 elements and does quick sort if so (but not for short inputs), then checks if it has over 1 element and does insertion sort (but not for short inputs).
So looks like this is already done.
I'm close this bug, but feel free to point out that I'm wrong if I'm misreading it.
Reply to this email directly or view it on GitHub: #9793 (comment)
mikioh
changed the title
Sort: the Sort function doesn't exit early for short inputs
sort: the Sort function doesn't exit early for short inputs
Feb 7, 2015
In func Sort(data Interface), we already call data.Len(). However we don't check to see if it returned a value < 2. We should, and if so, return immediately. As it is now, without this simple check, we end up allocating memory, regardless of whether or not we can do anything with the item passed.
Adding this check should have an insignificant impact on other calls to this function, since we're just doing a simple test on a variable we already have.
The text was updated successfully, but these errors were encountered: