diff options
author | Muhammad Qureshi <muhammadq@google.com> | 2020-01-15 13:35:41 -0800 |
---|---|---|
committer | Muhammad Qureshi <muhammadq@google.com> | 2020-01-15 13:35:41 -0800 |
commit | 996afa633ce5950c6d4afe7afc71d815e91efe66 (patch) | |
tree | beaa393998768d49f2124a7ec60e7539bffee218 /tools/stats_log_api_gen/java_writer.cpp | |
parent | 089d1bb28d9f933189ff377cb94df646e8f006ab (diff) |
Make writeKeyValuePairs accept Nullable args
API Review requested to remove unneeded allocations so pass null for
arguments that are empty when writing KeyValuePairs
Bug: 146383532
Test: m
Change-Id: Ic1788f65e8c7f837d6800d59c186519a82882bf7
Diffstat (limited to 'tools/stats_log_api_gen/java_writer.cpp')
-rw-r--r-- | tools/stats_log_api_gen/java_writer.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/tools/stats_log_api_gen/java_writer.cpp b/tools/stats_log_api_gen/java_writer.cpp index 7fa47f696b50..b09dcd5efb9c 100644 --- a/tools/stats_log_api_gen/java_writer.cpp +++ b/tools/stats_log_api_gen/java_writer.cpp @@ -142,16 +142,16 @@ static int write_java_methods( fprintf(out, "%s final int count = valueMap.size();\n", indent.c_str()); fprintf(out, - "%s final SparseIntArray intMap = new SparseIntArray();\n", + "%s SparseIntArray intMap = null;\n", indent.c_str()); fprintf(out, - "%s final SparseLongArray longMap = new SparseLongArray();\n", + "%s SparseLongArray longMap = null;\n", indent.c_str()); fprintf(out, - "%s final SparseArray<String> stringMap = new SparseArray<>();\n", + "%s SparseArray<String> stringMap = null;\n", indent.c_str()); fprintf(out, - "%s final SparseArray<Float> floatMap = new SparseArray<>();\n", + "%s SparseArray<Float> floatMap = null;\n", indent.c_str()); fprintf(out, "%s for (int i = 0; i < count; i++) {\n", indent.c_str()); @@ -163,18 +163,42 @@ static int write_java_methods( fprintf(out, "%s if (value instanceof Integer) {\n", indent.c_str()); fprintf(out, + "%s if (null == intMap) {\n", indent.c_str()); + fprintf(out, + "%s intMap = new SparseIntArray();\n", indent.c_str()); + fprintf(out, + "%s }\n", indent.c_str()); + fprintf(out, "%s intMap.put(key, (Integer) value);\n", indent.c_str()); fprintf(out, "%s } else if (value instanceof Long) {\n", indent.c_str()); fprintf(out, + "%s if (null == longMap) {\n", indent.c_str()); + fprintf(out, + "%s longMap = new SparseLongArray();\n", indent.c_str()); + fprintf(out, + "%s }\n", indent.c_str()); + fprintf(out, "%s longMap.put(key, (Long) value);\n", indent.c_str()); fprintf(out, "%s } else if (value instanceof String) {\n", indent.c_str()); fprintf(out, + "%s if (null == stringMap) {\n", indent.c_str()); + fprintf(out, + "%s stringMap = new SparseArray<>();\n", indent.c_str()); + fprintf(out, + "%s }\n", indent.c_str()); + fprintf(out, "%s stringMap.put(key, (String) value);\n", indent.c_str()); fprintf(out, "%s } else if (value instanceof Float) {\n", indent.c_str()); fprintf(out, + "%s if (null == floatMap) {\n", indent.c_str()); + fprintf(out, + "%s floatMap = new SparseArray<>();\n", indent.c_str()); + fprintf(out, + "%s }\n", indent.c_str()); + fprintf(out, "%s floatMap.put(key, (Float) value);\n", indent.c_str()); fprintf(out, "%s }\n", indent.c_str()); |