mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Replace RN Dev Tool perf logger usage of API 24 method in java.util.Comparator.naturalOrder
Summary: Previous diff D41486648 is causing crashes and a sev S311353, which is due to usages of an old Android API that only work after level 24 (D36500518 (https://github.com/facebook/react-native/commit/0fc42fd35c577c71825f020b0fa09bee6d9ad105)). ~~This diff updates the implementation to use a compatible API, but with worse runtime complexity.~~ ~~https://fburl.com/txd0r89e is a good explanation on the two algorithm to calculate a streaming median value. This diff uses the approach described in https://stackoverflow.com/a/4903642.~~ ## Update Following suggestion from sshic, I preserved the existing algorithm but with a custom comparator approach. Changelog: [Internal] Reviewed By: makovkastar Differential Revision: D41505143 fbshipit-source-id: 494e07fa627b5cf8bad7971fa5de86d270a7412c
This commit is contained in:
1 parent
0f089ea2db
commit
a3c47d3baa
1 file changed
+21
-2
@@ -21,8 +21,27 @@ import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
|
||||
class LongStreamingStats {
|
||||
private Queue<Long> minHeap = new PriorityQueue<>(Comparator.naturalOrder());
|
||||
private Queue<Long> maxHeap = new PriorityQueue<>(Comparator.reverseOrder());
|
||||
// TODO(T138627466): Calculate median value with better algorithm after Android API 24.
|
||||
private Queue<Long> minHeap =
|
||||
new PriorityQueue<>(
|
||||
11,
|
||||
new Comparator<Long>() {
|
||||
@Override
|
||||
public int compare(Long first, Long second) {
|
||||
// Natural order
|
||||
return Long.compare(first, second);
|
||||
}
|
||||
});
|
||||
private Queue<Long> maxHeap =
|
||||
new PriorityQueue<>(
|
||||
11,
|
||||
new Comparator<Long>() {
|
||||
@Override
|
||||
public int compare(Long first, Long second) {
|
||||
// Reversed order
|
||||
return Long.compare(second, first);
|
||||
}
|
||||
});
|
||||
private double streamingAverage = 0.0;
|
||||
private int len = 0;
|
||||
private long max = 0;
|
||||
|
||||
Reference in new issue
Block a user