Skip to content

Commit

Permalink
Avoid copying the field alias lookup structure unnecessarily. (elasti…
Browse files Browse the repository at this point in the history
…c#39726)

The field alias map is now only copied if a new alias is added, or if an alias
definition has changed. This follows the same behavior as we have for concrete
field mappings and avoids unnecessary object creation.
  • Loading branch information
jtibshirani authored Mar 12, 2019
1 parent ef18d3f commit 8e5ba9a
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ public FieldTypeLookup copyAndAddAll(String type,
MappedFieldType fieldType = fieldMapper.fieldType();
MappedFieldType fullNameFieldType = fullName.get(fieldType.name());

if (!Objects.equals(fieldType, fullNameFieldType)) {
if (Objects.equals(fieldType, fullNameFieldType) == false) {
fullName = fullName.copyAndPut(fieldType.name(), fieldType);
}
}

for (FieldAliasMapper fieldAliasMapper : fieldAliasMappers) {
String aliasName = fieldAliasMapper.name();
String path = fieldAliasMapper.path();
aliases = aliases.copyAndPut(aliasName, path);

String existingPath = aliases.get(aliasName);
if (Objects.equals(path, existingPath) == false) {
aliases = aliases.copyAndPut(aliasName, path);
}
}

return new FieldTypeLookup(fullName, aliases);
Expand Down

0 comments on commit 8e5ba9a

Please sign in to comment.