Skip to content

Commit

Permalink
[memory] intern ConfigurationElement.propertiesAndValue
Browse files Browse the repository at this point in the history
o.e.core.internal.registry.ConfigurationElement.propertiesAndValue
is likely to contain duplicate Strings like "true"
  • Loading branch information
EcljpseB0T committed Feb 22, 2024
1 parent 906f6d6 commit 98fd256
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* plug-in manifest.
*/
public class ConfigurationElement extends RegistryObject {

static final ConfigurationElement[] EMPTY_ARRAY = new ConfigurationElement[0];
private static final String[] EMPTY_STRINGS = new String[0];

// The id of the parent element. It can be a configuration element or an
// extension
Expand Down Expand Up @@ -60,7 +62,7 @@ protected ConfigurationElement(int self, String contributorId, String name, Stri
setObjectId(self);
this.contributorId = contributorId;
this.name = name;
this.propertiesAndValue = propertiesAndValue;
this.propertiesAndValue = intern(propertiesAndValue);
setRawChildren(children);
setExtraDataOffset(extraDataOffset);
parentId = parent;
Expand Down Expand Up @@ -110,14 +112,32 @@ protected String[] getAttributeNames() {
}

void setProperties(String[] value) {
propertiesAndValue = value;
propertiesAndValue = intern(value);
}

private static String[] intern(String[] a) {
if (a == null) {
return null;
}
if (a.length == 0) {
return EMPTY_STRINGS;
}
for (int i = 0; i < a.length; i++) {
a[i] = intern(a[i]);
}
return a;
}

private static String intern(String s) {
return s == null ? null : s.intern();
}

protected String[] getPropertiesAndValue() {
return propertiesAndValue;
}

void setValue(String value) {
value = intern(value);
if (propertiesAndValue.length == 0) {
propertiesAndValue = new String[] { value };
return;
Expand Down

0 comments on commit 98fd256

Please sign in to comment.