-
Notifications
You must be signed in to change notification settings - Fork 171
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
base: master
Are you sure you want to change the base?
Conversation
…ore efficiently""
if (acceptObjects == expTest.evaluate(attrVal, interpreter, expArgs)) { | ||
result.add(val); | ||
} | ||
} | ||
interpreter.getContext().removeResolvedExpression(expression); | ||
|
||
return result; | ||
} |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
return String.format("%s.%s", tempValue, expression).trim(); | |
return new StringBuilder() | |
.append(tempValue) | |
.append(".") | |
.append(expression) | |
.toString() | |
.trim(); |
Take 2. I will fix this up.