diff options
author | Googler <noreply@google.com> | 2016-05-15 18:30:52 +0000 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2016-05-16 15:17:00 +0000 |
commit | db89a643180895c0b9ca27911adf1ff692212d1c (patch) | |
tree | 09f928569cb11ef4eb70e3e1133c725a25ab6978 /src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java | |
parent | e37c55eccbd4516b2db7aaf58ef95209dfad3ed4 (diff) |
Memory Optimizations:
* Cache the FullyQualifiedName instances. Due to a very high number of duplicated resource keys, all FullyQualifiedNames should be effectively interned.
* Presume xliff in all resources. Inlining the xmlns is a bit costly.
--
MOS_MIGRATED_REVID=122375955
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java index 3a0eefc3c9..9c27f044bd 100644 --- a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java +++ b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java @@ -56,6 +56,7 @@ import javax.xml.stream.events.XMLEvent; * declared inside the <resources> tag. */ public class XmlResourceValues { + private static final Logger logger = Logger.getLogger(XmlResourceValues.class.getCanonicalName()); private static final QName TAG_EAT_COMMENT = QName.valueOf("eat-comment"); @@ -73,6 +74,9 @@ public class XmlResourceValues { private static final QName ATTR_PARENT = QName.valueOf("parent"); private static final QName ATTR_TYPE = QName.valueOf("type"); + static final String XLIFF_NAMESPACE = "urn:oasis:names:tc:xliff:document:1.2"; + private static final String XLIFF_PREFIX = "xliff"; + static XmlResourceValue parsePlurals(XMLEventReader eventReader) throws XMLStreamException { ImmutableMap.Builder<String, String> values = ImmutableMap.builder(); for (XMLEvent element = nextTag(eventReader); @@ -170,10 +174,14 @@ public class XmlResourceValues { } String value = escapeXmlValues(attribute.getValue()).replace("\"", """); if (!name.getNamespaceURI().isEmpty()) { - // Declare the xmlns here, so that the written xml will be semantically correct, - // if a bit verbose. This allows the resource keys to be written into a generic <resources> - // tag. - attributeMap.put("xmlns:" + name.getPrefix(), name.getNamespaceURI()); + // xliff is always provided on resources to help with file size + if (!(XLIFF_NAMESPACE.equals(name.getNamespaceURI()) + && XLIFF_PREFIX.equals(name.getPrefix()))) { + // Declare the xmlns here, so that the written xml will be semantically correct, + // if a bit verbose. This allows the resource keys to be written into a <resources> + // tag without a global namespace. + attributeMap.put("xmlns:" + name.getPrefix(), name.getNamespaceURI()); + } attributeMap.put(name.getPrefix() + ":" + attribute.getName().getLocalPart(), value); } else { attributeMap.put(attribute.getName().getLocalPart(), value); |