Fix event dispatcher timestamp sorting bug

Summary:Turns out even using nanoseconds as timestamps will not guarantee that events
won't happen at the same time. This fixes sorting for event comparison.

Differential Revision: D3030540

fb-gh-sync-id: 2630c50ea60a792ea07b1bf1c6cd46a6d9859268
shipit-source-id: 2630c50ea60a792ea07b1bf1c6cd46a6d9859268
This commit is contained in:
Andrei Coman
2016-03-09 12:40:35 -08:00
committed by Facebook Github Bot 6
parent a1821ae523
commit f5a349021d

View File

@@ -13,7 +13,6 @@ import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
@@ -75,7 +74,14 @@ public class EventDispatcher implements LifecycleEventListener {
return 1;
}
return lhs.getTimestampMs() < rhs.getTimestampMs() ? -1 : 1;
long diff = lhs.getTimestampMs() - rhs.getTimestampMs();
if (diff == 0) {
return 0;
} else if (diff < 0) {
return -1;
} else {
return 1;
}
}
};