[PATCH] D48896: [libcxx][c++17] P0083R5: Splicing Maps and Sets Part 2: merge

Louis Dionne via Phabricator reviews at reviews.llvm.org
Wed Oct 24 14:21:54 PDT 2018


ldionne added a comment.

In https://reviews.llvm.org/D48896#1274938, @rsmith wrote:

> In https://reviews.llvm.org/D48896#1274919, @rsmith wrote:
>
> > We can only do that if the comparators divide elements into the same equivalence classes, which we cannot know in general. (We can do this optimization if we can prove the comparator is a pure stateless function, but we probably can't detect that -- even an empty class type could store its state outside the class.) However, if the source and destination have the same comparator, and that comparator is `std::less<T>`, then I think it's correct to do this optimization.
>
>
> Hmm, actually, we can probably do this in more cases than that. If we use the *destination's* comparator to check for equivalent elements instead of the source's comparator (under the assumption that the destination order is usually the same as the source order), this would work.


Using the destination's comparator to perform this optimization is clever, and I believe it would work. This is much better than using the source's comparator when `std::is_empty<SourceComparator>` and `std::is_same<SourceComparator, DestinationComparator>` are both true.

> But more generally, can we just provide the location of the most-recently-inserted element as an insertion hint and get this optimization as a special case of a more general optimization? But maybe that's actually what you were suggesting (the difference is hidden behind the "key in the source is not equivalent to the [other] key" comments -- equivalent according to which comparator?).

The insertion hint idea did cross my mind when I was thinking about this but I did not pursue it further. I think it may be a cleaner way to achieve what I'm suggesting.


https://reviews.llvm.org/D48896





More information about the libcxx-commits mailing list