mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-09 09:30:10 +08:00
Add new FileSourceProvider
Summary: Add a new interface to JSC that allows loading a file lazily from disk, i.e. using mmap, instead of loading the whole file upfront and copying into the VM. Reviewed By: michalgr Differential Revision: D3534042 fbshipit-source-id: 98b193cc7b7e33248073e2556ea94ce3391507c7
This commit is contained in:
committed by
Facebook Github Bot 9
parent
e5650560c0
commit
5d06918d07
@@ -412,9 +412,12 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
}
|
||||
|
||||
private void recreateReactContextInBackgroundFromBundleFile() {
|
||||
boolean useLazyBundle = mJSCConfig.getConfigMap().hasKey("useLazyBundle") ?
|
||||
mJSCConfig.getConfigMap().getBoolean("useLazyBundle") : false;
|
||||
|
||||
recreateReactContextInBackground(
|
||||
new JSCJavaScriptExecutor.Factory(mJSCConfig.getConfigMap()),
|
||||
JSBundleLoader.createFileLoader(mApplicationContext, mJSBundleFile));
|
||||
JSBundleLoader.createFileLoader(mApplicationContext, mJSBundleFile, useLazyBundle));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -161,7 +161,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
MessageQueueThread moduleQueue,
|
||||
ModuleRegistryHolder registryHolder);
|
||||
|
||||
/* package */ native void loadScriptFromAssets(AssetManager assetManager, String assetURL);
|
||||
/* package */ native void loadScriptFromAssets(AssetManager assetManager, String assetURL, boolean useLazyBundle);
|
||||
/* package */ native void loadScriptFromFile(String fileName, String sourceURL);
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,11 +28,18 @@ public abstract class JSBundleLoader {
|
||||
public static JSBundleLoader createFileLoader(
|
||||
final Context context,
|
||||
final String fileName) {
|
||||
return createFileLoader(context, fileName, false);
|
||||
}
|
||||
|
||||
public static JSBundleLoader createFileLoader(
|
||||
final Context context,
|
||||
final String fileName,
|
||||
final boolean useLazyBundle) {
|
||||
return new JSBundleLoader() {
|
||||
@Override
|
||||
public void loadScript(CatalystInstanceImpl instance) {
|
||||
if (fileName.startsWith("assets://")) {
|
||||
instance.loadScriptFromAssets(context.getAssets(), fileName);
|
||||
instance.loadScriptFromAssets(context.getAssets(), fileName, useLazyBundle);
|
||||
} else {
|
||||
instance.loadScriptFromFile(fileName, fileName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user