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

Use String.repeat() and pattern matching instanceof #27834

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public void setValues(PreparedStatement ps) throws SQLException {
if (this.args != null && this.argTypes != null) {
for (int i = 0; i < this.args.length; i++) {
Object arg = this.args[i];
if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) {
Collection<?> entries = (Collection<?>) arg;
if (arg instanceof Collection<?> entries && this.argTypes[i] != Types.ARRAY) {
for (Object entry : entries) {
if (entry instanceof Object[] valueArray) {
for (Object argValue : valueArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ public void setValues(PreparedStatement ps) throws SQLException {
}
declaredParameter = declaredParameters.get(i);
}
if (in instanceof Iterable && declaredParameter.getSqlType() != Types.ARRAY) {
Iterable<?> entries = (Iterable<?>) in;
if (in instanceof Iterable<?> entries && declaredParameter.getSqlType() != Types.ARRAY) {
for (Object entry : entries) {
if (entry instanceof Object[] valueArray) {
for (Object argValue : valueArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,7 @@ public String nextStringValue() throws DataAccessException {
String s = Long.toString(getNextKey());
int len = s.length();
if (len < this.paddingLength) {
StringBuilder sb = new StringBuilder(this.paddingLength);
for (int i = 0; i < this.paddingLength - len; i++) {
sb.append('0');
}
sb.append(s);
s = sb.toString();
s = "0".repeat(this.paddingLength - len) + s;

Choose a reason for hiding this comment

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

This may be less efficient due to the need for allocation of a temporary String.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

JMH says otherwise
изображение

Choose a reason for hiding this comment

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

Consider attaching benchmark's code

}
return s;
}
Expand Down