From 8fb6111fa54db407199f6b86615f1fae65c0c8e4 Mon Sep 17 00:00:00 2001 From: Adam Ernst Date: Mon, 11 Jul 2016 13:14:17 -0700 Subject: [PATCH] Make loadRAMBundle a C function, not a method Summary: This makes the state it uses more explicit. It also makes a bug with performance measurement obvious: if we early return to error, we never mark stop for `RCTPLRAMStartupCodeSize`. Reviewed By: javache Differential Revision: D3542751 fbshipit-source-id: e6c1e3f3a76098ca37b8078f6e9abc805ad2d9da --- React/Executors/RCTJSCExecutor.mm | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/React/Executors/RCTJSCExecutor.mm b/React/Executors/RCTJSCExecutor.mm index 9e6579f2d..b3fe9d897 100644 --- a/React/Executors/RCTJSCExecutor.mm +++ b/React/Executors/RCTJSCExecutor.mm @@ -666,8 +666,12 @@ static void installBasicSynchronousHooksOnContext(JSContext *context) uint32_t magicNumber = NSSwapLittleIntToHost(*((uint32_t *)script.bytes)); BOOL isRAMBundle = magicNumber == RCTRAMBundleMagicNumber; if (isRAMBundle) { + [_performanceLogger markStartForTag:RCTPLRAMBundleLoad]; NSError *error; - script = [self loadRAMBundle:sourceURL error:&error]; + script = loadRAMBundle(sourceURL, &error, _randomAccessBundle); + [self registerNativeRequire]; + [_performanceLogger markStopForTag:RCTPLRAMBundleLoad]; + [_performanceLogger setValue:script.length forTag:RCTPLRAMStartupCodeSize]; if (error) { if (onComplete) { @@ -892,9 +896,8 @@ static RandomAccessBundleStartupCode readRAMBundle(file_ptr bundle, RandomAccess return {std::move(code), startupCodeSize}; } -- (NSData *)loadRAMBundle:(NSURL *)sourceURL error:(NSError **)error +static NSData *loadRAMBundle(NSURL *sourceURL, NSError **error, RandomAccessBundleData &randomAccessBundle) { - [_performanceLogger markStartForTag:RCTPLRAMBundleLoad]; file_ptr bundle(fopen(sourceURL.path.UTF8String, "r"), fclose); if (!bundle) { if (error) { @@ -903,10 +906,7 @@ static RandomAccessBundleStartupCode readRAMBundle(file_ptr bundle, RandomAccess return nil; } - [self registerNativeRequire]; - - - auto startupCode = readRAMBundle(std::move(bundle), _randomAccessBundle); + auto startupCode = readRAMBundle(std::move(bundle), randomAccessBundle); if (startupCode.isEmpty()) { if (error) { *error = RCTErrorWithMessage(@"Error loading RAM Bundle"); @@ -914,8 +914,6 @@ static RandomAccessBundleStartupCode readRAMBundle(file_ptr bundle, RandomAccess return nil; } - [_performanceLogger markStopForTag:RCTPLRAMBundleLoad]; - [_performanceLogger setValue:startupCode.size forTag:RCTPLRAMStartupCodeSize]; return [NSData dataWithBytesNoCopy:startupCode.code.release() length:startupCode.size freeWhenDone:YES]; }