Skip to content

Commit

Permalink
Reduce allocations on RuntimeDeploymentManager.MappersKey
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Feb 2, 2023
1 parent 97ba0c3 commit e828d27
Showing 1 changed file with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,22 +278,35 @@ private static class MappersKey implements Comparable<MappersKey> {
public MappersKey(URITemplate path) {
this.path = path;

// create a key without any names. Names of e.g. default regex components can differ, but the component still has the same meaning.
StringBuilder keyBuilder = new StringBuilder();
for (URITemplate.TemplateComponent component : path.components) {
keyBuilder.append(component.type);
keyBuilder.append(";");
keyBuilder.append(component.literalText);
keyBuilder.append(";");
if (component.pattern != null) {
// (?<id1>[a-zA-Z]+) -> [a-zA-Z]+
String pattern = component.pattern.pattern();
keyBuilder.append(component.pattern.pattern(), pattern.indexOf('>') + 1, pattern.length() - 1);
if (path.components.length == 0) {
this.key = "";
} else {
// create a key without any names. Names of e.g. default regex components can differ, but the component still has the same meaning.
StringBuilder keyBuilder = new StringBuilder();
for (URITemplate.TemplateComponent component : path.components) {
int standardLength = component.type.name().length() + 1
+ (component.literalText != null ? component.literalText.length() : 0) + 1 + 1;
int additionalLength = 0;
if (component.pattern != null) {
additionalLength = component.pattern.pattern().length();
}
StringBuilder kb = new StringBuilder(standardLength + additionalLength);
kb.append(component.type);
kb.append(";");
kb.append(component.literalText);
kb.append(";");
if (component.pattern != null) {
// (?<id1>[a-zA-Z]+) -> [a-zA-Z]+
String pattern = component.pattern.pattern();
kb.append(component.pattern.pattern(), pattern.indexOf('>') + 1, pattern.length() - 1);
}
kb.append("|");
keyBuilder.append(kb);
}
keyBuilder.append("|");

this.key = keyBuilder.toString();
}

this.key = keyBuilder.toString();
}

@Override
Expand Down

0 comments on commit e828d27

Please sign in to comment.