Sitelet https://github.com/spring-projects/spring-framework/pull/22299
Skip to content

DRY: use existing method Type::getInternalName in Type::appendDescriptor - #22299

Closed
stsypanov wants to merge 1 commit into
spring-projects:masterfrom
stsypanov:master
Closed

stsypanov wants to merge 1 commit into
spring-projects:masterfrom
stsypanov:master

Conversation

@stsypanov

Copy link
Copy Markdown
Contributor
String name = currentClass.getName();
int nameLength = name.length();
for (int i = 0; i < nameLength; ++i) {
  char car = name.charAt(i);
  stringBuilder.append(car == '.' ? '/' : car);
}

this code appends the name of currentClass having all dots replaced with '/'. However the same class already contains method doing exactly the same

public static String getInternalName(final Class<?> clazz) {
  return clazz.getName().replace('.', '/');
}

This one is not only more readable and likely to be faster as it yields the whole String at once instead of appending char by char inflating original StringBuilder.

@jhoeller

Copy link
Copy Markdown
Contributor

You have a point there. However, this code is a repackaged fork of https://gitlab.ow2.org/asm/asm/commits/master, so any such refactorings should really start there... and we'll automatically pick it up for our fork at our next sync point then.

@jhoeller jhoeller closed this Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants