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

Support expressions in selectattr/rejectattr again, more efficiently v2 #454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mattcoley
Copy link
Collaborator

Take 2. I will fix this up.

if (acceptObjects == expTest.evaluate(attrVal, interpreter, expArgs)) {
result.add(val);
}
}
interpreter.getContext().removeResolvedExpression(expression);

return result;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an unused method parameter in this method. Should we remove it? Map<String, Object> kwargs

}

private String generateTempVariable(String tempValue, String expression) {
return String.format("%s.%s", tempValue, expression).trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

The String.format has some performance issues. So, for curiosity, I ran a benchmark to compare the approaches.

Those are the results:

Benchmark                                                Mode  Cnt   Score   Error  Units
StringConcatSimulation.concatWithConcatFunction            ss   25   1.900 ± 0.120  ms/op
StringConcatSimulation.concatWithPlus                      ss   25   2.079 ± 0.438  ms/op
StringConcatSimulation.concatWithStringBuilder             ss   25   1.871 ± 0.436  ms/op
StringConcatSimulation.concatWithStringBuilderWithCount    ss   25   1.720 ± 0.255  ms/op
StringConcatSimulation.concatWithStringFormat              ss   25  15.145 ± 2.836  ms/op

I would suggest using StringBuilder instead.

Suggested change
return String.format("%s.%s", tempValue, expression).trim();
return new StringBuilder()
.append(tempValue)
.append(".")
.append(expression)
.toString()
.trim();

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