osteslag / Changeset

Minimal edits from one collection to another
MIT License
802 stars 46 forks source link

Minor Generic and Guard changes #3

Closed perlfly closed 8 years ago

perlfly commented 8 years ago

Remove force cast to Int adding Generic constraint for CollectionType Move guard conditions in editDistance at the top of the function

perlfly commented 8 years ago

I admit that my guard changes look a bit ugly. Reasons why I proposed a change are:

Maybe I'll try another solution for moving up the guards. Please, if I do, don't consider it as me trying to force that change ... just reasoning about it and open to your opinions.

osteslag commented 8 years ago

While I’d definitely like to exit earlier, the value of the only slightly earlier exist was not justified by the duplicated code and marginal memory optimisation, in my opinion.

The for loops come quite early – after the d allocation, yes, but it only allocates the amount of memory needed anyway. Just like your code.

A much more relevant optimisation, I think, would be to make the Changeset.edits property lazy. The user may have a bunch of Changeset values in the air, and may only be querying the edits on some of those. It would be a waste to have computed the edit distances in those unused cases. But I haven’t found a way to do that in Swift 2.

perlfly commented 8 years ago

:+1: Thanks