Preserve the compared elements order
Merge from upstream