documentcloud/backbone — pull request #1754 by byroot (2012-10-19 15:08:33+00:00)
Title: Avoid triggering a sort in some cases

If all models provided to Collection.add are duplicates and we don't want to merge them, then it's useless to sort the collection.

In my case the collection sorting take around 30ms (dynamic sorting on text field with String.localeCompare on a ~800 items collection).

Right now to save these computation i'm forced to check for duplicates before calling Collection.add:

```coffescript
@collection.add(model) unless @collection.get(model.id)
```

In that case I know that if `model`is in `@collection` its the same instance.