From 77752a0399070a71fd62b4e370c8e27f838a4378 Mon Sep 17 00:00:00 2001 From: Adam Ernst Date: Thu, 7 Jul 2016 13:31:20 -0700 Subject: [PATCH] Move locals closer to point they are used Summary: No need to have these way at the top; they're not used until later. Reviewed By: majak Differential Revision: D3518364 fbshipit-source-id: 3e7461665e90dea5c6d323d45b1ffb11fb610b09 --- React/Base/RCTJavaScriptLoader.m | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/React/Base/RCTJavaScriptLoader.m b/React/Base/RCTJavaScriptLoader.m index 8ea430702..c4341844f 100755 --- a/React/Base/RCTJavaScriptLoader.m +++ b/React/Base/RCTJavaScriptLoader.m @@ -42,16 +42,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) // Load local script file if (scriptURL.fileURL) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - NSError *error = nil; - NSData *source = nil; - // Load the first 4 bytes to check if the bundle is regular or RAM ("Random Access Modules" bundle). // The RAM bundle has a magic number in the 4 first bytes `(0xFB0BD1E5)`. // The benefit of RAM bundle over a regular bundle is that we can lazily inject // modules into JSC as they're required. FILE *bundle = fopen(scriptURL.path.UTF8String, "r"); if (!bundle) { - onComplete(RCTErrorWithMessage([NSString stringWithFormat:@"Error opening bundle %@", scriptURL.path]), source, 0); + onComplete(RCTErrorWithMessage([NSString stringWithFormat:@"Error opening bundle %@", scriptURL.path]), nil, 0); return; } @@ -59,12 +56,14 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) size_t readResult = fread(&magicNumber, sizeof(magicNumber), 1, bundle); fclose(bundle); if (readResult != 1) { - onComplete(RCTErrorWithMessage(@"Error reading bundle"), source, 0); + onComplete(RCTErrorWithMessage(@"Error reading bundle"), nil, 0); return; } magicNumber = NSSwapLittleIntToHost(magicNumber); + NSError *error = nil; + NSData *source = nil; int64_t sourceLength = 0; if (magicNumber == RCTRAMBundleMagicNumber) { source = [NSData dataWithBytes:&magicNumber length:sizeof(magicNumber)];