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:
ransj 2016-09-15 15:31:40 -07:00 committed by Facebook Github Bot 3
parent 3b5e4cc593
commit 44b0e6b91f
2 changed files with 11 additions and 28 deletions

View File

@ -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) {

View File

@ -13,7 +13,7 @@ import com.facebook.react.bridge.ReadableMapKeySetIterator;
public class ViewManagerPropertyUpdater {
public interface Settable {
Map<String, String> getProperties();
void getProperties(Map<String, String> props);
}
public interface ViewManagerSetter<T extends ViewManager, V extends View> extends Settable {
@ -57,8 +57,8 @@ public class ViewManagerPropertyUpdater {
Class<? extends ViewManager> viewManagerTopClass,
Class<? extends ReactShadowNode> shadowNodeTopClass) {
Map<String, String> props = new HashMap<>();
props.putAll(findManagerSetter(viewManagerTopClass).getProperties());
props.putAll(findNodeSetter(shadowNodeTopClass).getProperties());
findManagerSetter(viewManagerTopClass).getProperties(props);
findNodeSetter(shadowNodeTopClass).getProperties(props);
return props;
}
@ -125,12 +125,10 @@ public class ViewManagerPropertyUpdater {
}
@Override
public Map<String, String> getProperties() {
Map<String, String> nativeProps = new HashMap<>();
public void getProperties(Map<String, String> props) {
for (ViewManagersPropertyCache.PropSetter setter : mPropSetters.values()) {
nativeProps.put(setter.getPropName(), setter.getPropType());
props.put(setter.getPropName(), setter.getPropType());
}
return nativeProps;
}
}
@ -152,12 +150,10 @@ public class ViewManagerPropertyUpdater {
}
@Override
public Map<String, String> getProperties() {
Map<String, String> nativeProps = new HashMap<>();
public void getProperties(Map<String, String> props) {
for (ViewManagersPropertyCache.PropSetter setter : mPropSetters.values()) {
nativeProps.put(setter.getPropName(), setter.getPropType());
props.put(setter.getPropName(), setter.getPropType());
}
return nativeProps;
}
}
}