Simplify ViewManagerOnDemandReactPackage.getViewManagerNames to return Collection

Summary:
This way we can avoid unnecessary ArrayList copies.

Changelog: [Android][Changed] Generalized the return type of ViewManagerOnDemandReactPackage.getViewManagerNames

Reviewed By: nlutsenko

Differential Revision: D36131516

fbshipit-source-id: 6a42c76cadbcce4c3720875d80062e1ee237bc2f
This commit is contained in:
Pieter De Baets
2022-05-13 06:50:04 -07:00
committed by Facebook GitHub Bot
parent d7921f0504
commit 51e029ec3c
6 changed files with 18 additions and 17 deletions
@@ -159,7 +159,7 @@ public class ReactInstanceManager {
private final JavaScriptExecutorFactory mJavaScriptExecutorFactory;
// See {@code ReactInstanceManagerBuilder} for description of all flags here.
private @Nullable List<String> mViewManagerNames = null;
private @Nullable Collection<String> mViewManagerNames = null;
private final @Nullable JSBundleLoader mBundleLoader;
private final @Nullable String mJSMainModulePath; /* path to JS bundle root on Metro */
private final List<ReactPackage> mPackages;
@@ -962,9 +962,9 @@ public class ReactInstanceManager {
return null;
}
public @Nullable List<String> getViewManagerNames() {
public Collection<String> getViewManagerNames() {
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstanceManager.getViewManagerNames");
List<String> viewManagerNames = mViewManagerNames;
Collection<String> viewManagerNames = mViewManagerNames;
if (viewManagerNames != null) {
return viewManagerNames;
}
@@ -972,7 +972,7 @@ public class ReactInstanceManager {
synchronized (mReactContextLock) {
context = (ReactApplicationContext) getCurrentReactContext();
if (context == null || !context.hasActiveReactInstance()) {
return null;
return Collections.emptyList();
}
}
@@ -985,7 +985,7 @@ public class ReactInstanceManager {
.arg("Package", reactPackage.getClass().getSimpleName())
.flush();
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
List<String> names =
Collection<String> names =
((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(context);
if (names != null) {
uniqueNames.addAll(names);
@@ -994,7 +994,7 @@ public class ReactInstanceManager {
SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
}
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
mViewManagerNames = new ArrayList<>(uniqueNames);
mViewManagerNames = uniqueNames;
}
return mViewManagerNames;
}