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
This commit is contained in:
Adam Ernst
2016-07-07 13:31:20 -07:00
committed by Facebook Github Bot 2
parent b3ac5f06d2
commit 77752a0399

View File

@@ -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)];