mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
optimize getNativeProps method
Summary: The original method getNativeProps in ViewManagerPropertyUpdater.java create more HashMaps and putAll method need to re-hash the key again to avoid conflicts. This pull request pass the map as params to avoid the problem and update ReactPropertyProcessor.java to adapt the change. Closes https://github.com/facebook/react-native/pull/9916 Differential Revision: D3873152 fbshipit-source-id: 089840e5272265662cdbf58d88580f9203153b69
This commit is contained in:
committed by
Facebook Github Bot 3
parent
3b5e4cc593
commit
44b0e6b91f
+4
-17
@@ -245,7 +245,8 @@ public class ReactPropertyProcessor extends AbstractProcessor {
|
||||
MethodSpec getMethods = MethodSpec.methodBuilder("getProperties")
|
||||
.addModifiers(PUBLIC)
|
||||
.addAnnotation(Override.class)
|
||||
.returns(PROPERTY_MAP_TYPE)
|
||||
.addParameter(PROPERTY_MAP_TYPE, "props")
|
||||
.returns(TypeName.VOID)
|
||||
.addCode(generateGetProperties(properties))
|
||||
.build();
|
||||
|
||||
@@ -397,19 +398,7 @@ public class ReactPropertyProcessor extends AbstractProcessor {
|
||||
|
||||
private static CodeBlock generateGetProperties(List<PropertyInfo> properties)
|
||||
throws ReactPropertyException {
|
||||
if (properties.isEmpty()) {
|
||||
return CodeBlock.builder()
|
||||
.addStatement("return $T.emptyMap()", Collections.class)
|
||||
.build();
|
||||
}
|
||||
|
||||
CodeBlock.Builder builder = CodeBlock.builder()
|
||||
.addStatement(
|
||||
"$T props = new $T($L)",
|
||||
PROPERTY_MAP_TYPE,
|
||||
CONCRETE_PROPERTY_MAP_TYPE,
|
||||
properties.size());
|
||||
|
||||
CodeBlock.Builder builder = CodeBlock.builder();
|
||||
for (PropertyInfo propertyInfo : properties) {
|
||||
try {
|
||||
String typeName = getPropertypTypeName(propertyInfo.mProperty, propertyInfo.propertyType);
|
||||
@@ -419,9 +408,7 @@ public class ReactPropertyProcessor extends AbstractProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
return builder
|
||||
.addStatement("return props")
|
||||
.build();
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static String getPropertypTypeName(Property property, TypeName propertyType) {
|
||||
|
||||
Reference in New Issue
Block a user