Skip to content

Commit 7b20327

Browse files
authoredMar 13, 2025··
Merge pull request #919 from jeffgbutler/make-less-garbage
Little optimization that creates less garbage
2 parents ec526aa + 5eda6cb commit 7b20327

8 files changed

+18
-40
lines changed
 

‎src/main/java/org/mybatis/dynamic/sql/util/StringUtilities.java

-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,5 @@ static String toCamelCase(String inputString) {
5858
static String formatConstantForSQL(String in) {
5959
String escaped = in.replace("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
6060
return "'" + escaped + "'"; //$NON-NLS-1$ //$NON-NLS-2$
61-
6261
}
6362
}

‎src/main/java/org/mybatis/dynamic/sql/util/Utilities.java

-13
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,10 @@
1515
*/
1616
package org.mybatis.dynamic.sql.util;
1717

18-
import java.util.Collection;
19-
import java.util.Objects;
20-
import java.util.stream.Stream;
21-
22-
import org.jspecify.annotations.NonNull;
2318
import org.jspecify.annotations.Nullable;
2419

2520
public interface Utilities {
2621
static long safelyUnbox(@Nullable Long l) {
2722
return l == null ? 0 : l;
2823
}
29-
30-
static <T> Stream<@NonNull T> filterNullValues(Stream<@Nullable T> values) {
31-
return values.filter(Objects::nonNull);
32-
}
33-
34-
static <T> Collection<@NonNull T> removeNullElements(Collection<@Nullable T> values) {
35-
return filterNullValues(values.stream()).toList();
36-
}
3724
}

‎src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitive.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public static IsInCaseInsensitive of(String... values) {
7070
}
7171

7272
public static IsInCaseInsensitive of(Collection<String> values) {
73-
// Keep the null safe upper case utility for backwards compatibility
74-
//noinspection DataFlowIssue
75-
return new IsInCaseInsensitive(values).map(StringUtilities::safelyUpperCase);
73+
// Keep the null safe upper case utility for backwards compatibility in case someone passes in a null
74+
return new IsInCaseInsensitive(values.stream().map(StringUtilities::safelyUpperCase).toList());
7675
}
7776
}

‎src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
import java.util.Arrays;
1919
import java.util.Collection;
2020
import java.util.Collections;
21+
import java.util.Objects;
2122
import java.util.function.Predicate;
2223
import java.util.function.UnaryOperator;
2324

2425
import org.jspecify.annotations.Nullable;
2526
import org.mybatis.dynamic.sql.AbstractListValueCondition;
26-
import org.mybatis.dynamic.sql.util.StringUtilities;
27-
import org.mybatis.dynamic.sql.util.Utilities;
2827

2928
public class IsInCaseInsensitiveWhenPresent extends AbstractListValueCondition<String>
3029
implements CaseInsensitiveRenderableCondition {
@@ -35,8 +34,8 @@ public static IsInCaseInsensitiveWhenPresent empty() {
3534
return EMPTY;
3635
}
3736

38-
protected IsInCaseInsensitiveWhenPresent(Collection<@Nullable String> values) {
39-
super(Utilities.removeNullElements(values));
37+
protected IsInCaseInsensitiveWhenPresent(Collection<String> values) {
38+
super(values);
4039
}
4140

4241
@Override
@@ -66,8 +65,7 @@ public static IsInCaseInsensitiveWhenPresent of(@Nullable String... values) {
6665
}
6766

6867
public static IsInCaseInsensitiveWhenPresent of(Collection<@Nullable String> values) {
69-
// Keep the null safe upper case utility for backwards compatibility
70-
//noinspection DataFlowIssue
71-
return new IsInCaseInsensitiveWhenPresent(values).map(StringUtilities::safelyUpperCase);
68+
return new IsInCaseInsensitiveWhenPresent(
69+
values.stream().filter(Objects::nonNull).map(String::toUpperCase).toList());
7270
}
7371
}

‎src/main/java/org/mybatis/dynamic/sql/where/condition/IsLikeCaseInsensitive.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public IsLikeCaseInsensitive map(UnaryOperator<String> mapper) {
6767
}
6868

6969
public static IsLikeCaseInsensitive of(String value) {
70-
// Keep the null safe upper case utility for backwards compatibility
71-
//noinspection DataFlowIssue
72-
return new IsLikeCaseInsensitive(value).map(StringUtilities::safelyUpperCase);
70+
// Keep the null safe upper case utility for backwards compatibility in case someone passes in a null
71+
return new IsLikeCaseInsensitive(StringUtilities.safelyUpperCase(value));
7372
}
7473
}

‎src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitive.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public static IsNotInCaseInsensitive of(String... values) {
7070
}
7171

7272
public static IsNotInCaseInsensitive of(Collection<String> values) {
73-
// Keep the null safe upper case utility for backwards compatibility
74-
//noinspection DataFlowIssue
75-
return new IsNotInCaseInsensitive(values).map(StringUtilities::safelyUpperCase);
73+
// Keep the null safe upper case utility for backwards compatibility in case someone passes in a null
74+
return new IsNotInCaseInsensitive(values.stream().map(StringUtilities::safelyUpperCase).toList());
7675
}
7776
}

‎src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
import java.util.Arrays;
1919
import java.util.Collection;
2020
import java.util.Collections;
21+
import java.util.Objects;
2122
import java.util.function.Predicate;
2223
import java.util.function.UnaryOperator;
2324

2425
import org.jspecify.annotations.Nullable;
2526
import org.mybatis.dynamic.sql.AbstractListValueCondition;
26-
import org.mybatis.dynamic.sql.util.StringUtilities;
27-
import org.mybatis.dynamic.sql.util.Utilities;
2827

2928
public class IsNotInCaseInsensitiveWhenPresent extends AbstractListValueCondition<String>
3029
implements CaseInsensitiveRenderableCondition {
@@ -35,8 +34,8 @@ public static IsNotInCaseInsensitiveWhenPresent empty() {
3534
return EMPTY;
3635
}
3736

38-
protected IsNotInCaseInsensitiveWhenPresent(Collection<@Nullable String> values) {
39-
super(Utilities.removeNullElements(values));
37+
protected IsNotInCaseInsensitiveWhenPresent(Collection<String> values) {
38+
super(values);
4039
}
4140

4241
@Override
@@ -66,8 +65,7 @@ public static IsNotInCaseInsensitiveWhenPresent of(@Nullable String... values) {
6665
}
6766

6867
public static IsNotInCaseInsensitiveWhenPresent of(Collection<@Nullable String> values) {
69-
// Keep the null safe upper case utility for backwards compatibility
70-
//noinspection DataFlowIssue
71-
return new IsNotInCaseInsensitiveWhenPresent(values).map(StringUtilities::safelyUpperCase);
68+
return new IsNotInCaseInsensitiveWhenPresent(
69+
values.stream().filter(Objects::nonNull).map(String::toUpperCase).toList());
7270
}
7371
}

‎src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLikeCaseInsensitive.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public IsNotLikeCaseInsensitive map(UnaryOperator<String> mapper) {
6969
}
7070

7171
public static IsNotLikeCaseInsensitive of(String value) {
72-
// Keep the null safe upper case utility for backwards compatibility
73-
//noinspection DataFlowIssue
74-
return new IsNotLikeCaseInsensitive(value).map(StringUtilities::safelyUpperCase);
72+
// Keep the null safe upper case utility for backwards compatibility in case someone passes in a null
73+
return new IsNotLikeCaseInsensitive(StringUtilities.safelyUpperCase(value));
7574
}
7675
}

0 commit comments

Comments
 (0)
Please sign in to comment.