mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Stop using RCTConvert to convert between primitive types
Summary: RCTTiming was the only NativeModule that relied on converting `double`s to other `double`s via `RCTConvert`. RCTTiming was made into a regular NativeModule in D18410788, so it's safe to strip out this logic. Hopefully, this reduces the memory consumption enough to reduce the OOMs reported in T45151932. Changelog: [iOS][Removed] - Stop using RCTConvert to convert between primitive types Reviewed By: fkgozali Differential Revision: D18506069 fbshipit-source-id: 7316ad86bc84d47fb383735126d5b00e5491b371
This commit is contained in:
committed by
Facebook Github Bot
parent
ca3c8b7a7d
commit
8797a5cfcb
@@ -482,48 +482,6 @@ NSInvocation *ObjCTurboModule::getMethodInvocation(
|
||||
if (arg->isBool()) {
|
||||
bool v = arg->getBool();
|
||||
|
||||
/**
|
||||
* Convert numbers using RCTConvert if possible.
|
||||
*/
|
||||
NSString *methodNameNSString = @(methodName.c_str());
|
||||
NSString *argumentType = getArgumentTypeName(methodNameNSString, i);
|
||||
|
||||
if (argumentType != nil) {
|
||||
NSString *rctConvertMethodName = [NSString stringWithFormat:@"%@:", argumentType];
|
||||
SEL rctConvertSelector = NSSelectorFromString(rctConvertMethodName);
|
||||
|
||||
if ([RCTConvert respondsToSelector:rctConvertSelector]) {
|
||||
if (objCArgType == @encode(id)) {
|
||||
id (*convert)(id, SEL, id) = (__typeof__(convert))objc_msgSend;
|
||||
id convertedObjCArg = convert([RCTConvert class], rctConvertSelector, [NSNumber numberWithBool:v]);
|
||||
|
||||
[inv setArgument:(void *)&convertedObjCArg atIndex:i + 2];
|
||||
if (convertedObjCArg) {
|
||||
[retainedObjectsForInvocation addObject:convertedObjCArg];
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is necessary because RCTConvert could be responsible for converting BOOLs to
|
||||
* type aliases of BOOL.
|
||||
*/
|
||||
if (objCArgType == @encode(BOOL)) {
|
||||
BOOL (*convert)(id, SEL, id) = (__typeof__(convert))objc_msgSend;
|
||||
BOOL convertedObjCArg = convert([RCTConvert class], rctConvertSelector, [NSNumber numberWithBool:v]);
|
||||
[inv setArgument:(void *)&convertedObjCArg atIndex:i + 2];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
"Error when invoking TurboModule method " + name_ + "." + methodName + "(). Could not convert argument " +
|
||||
std::to_string(i) + " from JS boolean to ObjC type '" + std::to_string(objCArgType[0]) +
|
||||
"'. Supported types are BOOL (\"" + @encode(BOOL) + "\") and object (\"" + @encode(id) + "\").");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JS type checking ensures the Objective C argument here is either a BOOL or NSNumber*.
|
||||
*/
|
||||
@@ -541,53 +499,6 @@ NSInvocation *ObjCTurboModule::getMethodInvocation(
|
||||
if (arg->isNumber()) {
|
||||
double v = arg->getNumber();
|
||||
|
||||
/**
|
||||
* Convert numbers using RCTConvert if possible.
|
||||
*/
|
||||
NSString *methodNameNSString = @(methodName.c_str());
|
||||
NSString *argumentType = getArgumentTypeName(methodNameNSString, i);
|
||||
|
||||
if (argumentType != nil) {
|
||||
NSString *rctConvertMethodName = [NSString stringWithFormat:@"%@:", argumentType];
|
||||
SEL rctConvertSelector = NSSelectorFromString(rctConvertMethodName);
|
||||
|
||||
if ([RCTConvert respondsToSelector:rctConvertSelector]) {
|
||||
if (objCArgType == @encode(id)) {
|
||||
id (*convert)(id, SEL, id) = (__typeof__(convert))objc_msgSend;
|
||||
id convertedObjCArg = convert([RCTConvert class], rctConvertSelector, [NSNumber numberWithDouble:v]);
|
||||
|
||||
[inv setArgument:(void *)&convertedObjCArg atIndex:i + 2];
|
||||
if (convertedObjCArg) {
|
||||
[retainedObjectsForInvocation addObject:convertedObjCArg];
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is necessary because RCTConvert could be responsible for converting doubles to
|
||||
* type aliases of double. For example:
|
||||
*
|
||||
* Consider the following typedef:
|
||||
* typedef double NSTimeInterval;
|
||||
*
|
||||
* RCTConvert will convert our doubles to NSTimeInterval by dividing them by 1000.
|
||||
*/
|
||||
if (objCArgType == @encode(double)) {
|
||||
double (*convert)(id, SEL, id) = (__typeof__(convert))objc_msgSend;
|
||||
double convertedObjCArg = convert([RCTConvert class], rctConvertSelector, [NSNumber numberWithDouble:v]);
|
||||
[inv setArgument:(void *)&convertedObjCArg atIndex:i + 2];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
"Error when invoking TurboModule method " + name_ + "." + methodName + "(). Could not convert argument " +
|
||||
std::to_string(i) + " from JS number to ObjC type '" + std::to_string(objCArgType[0]) +
|
||||
"'. Supported types are double (\"" + @encode(double) + "\") and object (\"" + @encode(id) + "\").");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JS type checking ensures the Objective C argument here is either a double or NSNumber*.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user