Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: de-dupe attribute names during styles writing #3404

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;

public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializable {
Expand All @@ -47,6 +49,8 @@ public void serializeToResValuesXml(XmlSerializer serializer,
} else if (res.getResSpec().getName().indexOf('.') != -1) {
serializer.attribute(null, "parent", "");
}

Set<String> processedNames = new HashSet<>();
for (Duo<ResReferenceValue, ResScalarValue> mItem : mItems) {
ResResSpec spec = mItem.m1.getReferent();

Expand All @@ -70,6 +74,11 @@ public void serializeToResValuesXml(XmlSerializer serializer,
name = "@" + spec.getFullName(res.getResSpec().getPackage(), false);
}

// #3400 - Skip duplicate values, commonly seen are duplicate key-pairs on styles.
if (!isAnalysisMode() && processedNames.contains(name)) {
continue;
}

if (value == null) {
value = mItem.m2.encodeAsResXmlValue();
}
Expand All @@ -82,8 +91,11 @@ public void serializeToResValuesXml(XmlSerializer serializer,
serializer.attribute(null, "name", name);
serializer.text(value);
serializer.endTag(null, "item");

processedNames.add(name);
}
serializer.endTag(null, "style");
processedNames.clear();
}

private final Duo<ResReferenceValue, ResScalarValue>[] mItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public class ResValue {
public boolean shouldRemoveUnknownRes() {
return Config.getInstance().isDecodeResolveModeRemoving();
}

public boolean isAnalysisMode() {
return Config.getInstance().analysisMode;
}
}