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

Replace StringBuffer with StringBuilder, other minor String optimizations #382

Merged
merged 2 commits into from
May 12, 2022

Conversation

tim-hoffman
Copy link
Contributor

@tim-hoffman tim-hoffman commented Jul 16, 2021

Replace most uses of StringBuffer with StringBuilder to avoid the unnecessary synchronization from StringBuffer.
Replaced string concatenation within an append with multiple appends.
Remove unnecessary toString() calls on String instances.
Change length 1 string arguments of StringBuilder#append to character append (should have slightly better performance).

@@ -218,7 +218,7 @@ private String getMethodName(int opcode) {
break;
}

if (methodName.equals(""))
if ("".equals(methodName))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version is safe even if 'methodName' is null.

@@ -473,7 +473,7 @@ private void atWhileStmnt(Stmnt st, boolean notDo) throws CompileError {
boolean alwaysBranch = compileBooleanExpr(true, expr);
if (alwaysBranch) {
bytecode.addOpcode(Opcode.GOTO);
alwaysBranch = breakList.size() == 0;
alwaysBranch = breakList.isEmpty();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using isEmpty() should perform better compared to computing the entire size().

@chibash chibash merged commit 8fc31b8 into jboss-javassist:master May 12, 2022
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