Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

True, and it's a simple change to stop the comparison at either a NUL or a '&', so that it doesn't that extra unnecessary time.

The other two improvements I'd be looking to do are:

1) try to rework the insertion sort to make it use a binary search (if over a certain threshold that is yet to be determined by experimentation). Should be faster than looping through each element each time.

2) Not automatically extend the tail each time (where insertion somewhere between head and tail is required). The element being added may be one from the head so it's best to work out where it goes first and then pick the extension direction that requires the fewest number of elements to be shuffled up. Also the shuffling can be done in bulk using memmove() (can't use memcpy since the areas of memory will overlap when shuffling up by more than one position); this should also be faster than doing them one at a time.

Anyway, i'm off on holiday so I've got about another 15 minutes to look at this so I'm not going to get far. If I remember I'll try and check up on the status of it in github when I get back.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: