mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
Back out "[react-native][PR] There is a small gap in the SynchronizedWeakHashSet implementation. T?"
Summary: Original commit changeset: 2998bffb06e2 Reviewed By: JoshuaGross Differential Revision: D14689422 fbshipit-source-id: 2638bed8005859cc95972ba5f78a9e9cace878ef
This commit is contained in:
committed by
Facebook Github Bot
parent
5fa8258138
commit
d2981af68f
@@ -176,17 +176,14 @@ public class ReactContext extends ContextWrapper {
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
mLifecycleEventListeners.doIfContains(listener, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
listener.onHostResume();
|
||||
} catch (RuntimeException e) {
|
||||
handleException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!mLifecycleEventListeners.contains(listener)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
listener.onHostResume();
|
||||
} catch (RuntimeException e) {
|
||||
handleException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
@@ -24,15 +24,9 @@ public class SynchronizedWeakHashSet<T> {
|
||||
private Queue<Pair<T, Command>> mPendingOperations = new ArrayDeque<>();
|
||||
private boolean mIterating;
|
||||
|
||||
public void doIfContains(T item, Runnable runnable) {
|
||||
public boolean contains(T item) {
|
||||
synchronized (mMap) {
|
||||
if (mIterating) {
|
||||
mPendingOperations.add(new Pair<>(item, Command.newDoIfContains(runnable)));
|
||||
} else {
|
||||
if (mMap.containsKey(item)) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
return mMap.containsKey(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,19 +61,13 @@ public class SynchronizedWeakHashSet<T> {
|
||||
|
||||
while (!mPendingOperations.isEmpty()) {
|
||||
Pair<T, Command> pair = mPendingOperations.poll();
|
||||
Command command = pair.second;
|
||||
switch (command.getType()) {
|
||||
switch (pair.second) {
|
||||
case ADD:
|
||||
mMap.put(pair.first, null);
|
||||
break;
|
||||
case REMOVE:
|
||||
mMap.remove(pair.first);
|
||||
break;
|
||||
case DO_IF_CONTAINS:
|
||||
if (mMap.containsKey(pair.first)) {
|
||||
command.execute();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new AssertionException("Unsupported command" + pair.second);
|
||||
}
|
||||
@@ -91,40 +79,8 @@ public class SynchronizedWeakHashSet<T> {
|
||||
void iterate(T item);
|
||||
}
|
||||
|
||||
private enum CommandType {
|
||||
private enum Command {
|
||||
ADD,
|
||||
REMOVE,
|
||||
DO_IF_CONTAINS
|
||||
}
|
||||
|
||||
private static class Command {
|
||||
public static final Command ADD = new Command(CommandType.ADD);
|
||||
public static final Command REMOVE = new Command(CommandType.REMOVE);
|
||||
|
||||
private CommandType mType;
|
||||
private Runnable mRunnable;
|
||||
|
||||
public static Command newDoIfContains(Runnable runnable) {
|
||||
return new Command(CommandType.DO_IF_CONTAINS, runnable);
|
||||
}
|
||||
|
||||
private Command(CommandType type) {
|
||||
this(type, null);
|
||||
}
|
||||
|
||||
private Command(CommandType type, Runnable runnable) {
|
||||
mType = type;
|
||||
mRunnable = runnable;
|
||||
}
|
||||
|
||||
public CommandType getType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
if (mRunnable != null) {
|
||||
mRunnable.run();
|
||||
}
|
||||
}
|
||||
REMOVE
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user