mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fabric: Using pre-cached UIColor objects for black, white, and clear colors
Summary: This change maps the three most used colors (black, white, clear) to corresponding predefined values in UIColor. This should meaningfully reduce the overall amount of allocated UIColor/CGColor objects. In my non-scientific measures, it reduces the number of CGColor objects from ~1500 to ~1000. And... it no much at least in terms of kilobytes. However, I still think it's a good idea to implement this because I hope that can remove some work from memory allocation infra and maybe enable some optimizations that UIKit hopefully does for black and white colors. (I tend to believe that this optimization exists because UIKit even has a classes called UIDeviceWhiteColor and UICachedDeviceWhiteColor.) Changelog: [Internal] Fabric-specific internal change. Reviewed By: JoshuaGross Differential Revision: D23753506 fbshipit-source-id: 46e58dc7e6b0dcab3c83d29c7257c90ffbd95246
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e4877ed985
commit
5b93c49e76
@@ -35,12 +35,24 @@ inline std::string RCTStringFromNSString(NSString *string)
|
||||
return std::string{string.UTF8String ?: ""};
|
||||
}
|
||||
|
||||
inline UIColor *_Nullable RCTUIColorFromSharedColor(const facebook::react::SharedColor &sharedColor)
|
||||
inline UIColor *_Nullable RCTUIColorFromSharedColor(facebook::react::SharedColor const &sharedColor)
|
||||
{
|
||||
if (!sharedColor) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (*facebook::react::clearColor() == *sharedColor) {
|
||||
return [UIColor clearColor];
|
||||
}
|
||||
|
||||
if (*facebook::react::blackColor() == *sharedColor) {
|
||||
return [UIColor blackColor];
|
||||
}
|
||||
|
||||
if (*facebook::react::whiteColor() == *sharedColor) {
|
||||
return [UIColor whiteColor];
|
||||
}
|
||||
|
||||
auto components = facebook::react::colorComponentsFromColor(sharedColor);
|
||||
return [UIColor colorWithRed:components.red green:components.green blue:components.blue alpha:components.alpha];
|
||||
}
|
||||
|
||||
+13
-1
@@ -102,6 +102,18 @@ inline static UIColor *RCTUIColorFromSharedColor(const SharedColor &sharedColor)
|
||||
return nil;
|
||||
}
|
||||
|
||||
auto components = colorComponentsFromColor(sharedColor);
|
||||
if (*facebook::react::clearColor() == *sharedColor) {
|
||||
return [UIColor clearColor];
|
||||
}
|
||||
|
||||
if (*facebook::react::blackColor() == *sharedColor) {
|
||||
return [UIColor blackColor];
|
||||
}
|
||||
|
||||
if (*facebook::react::whiteColor() == *sharedColor) {
|
||||
return [UIColor whiteColor];
|
||||
}
|
||||
|
||||
auto components = facebook::react::colorComponentsFromColor(sharedColor);
|
||||
return [UIColor colorWithRed:components.red green:components.green blue:components.blue alpha:components.alpha];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user