Skip to content

Commit c168dd4

Browse files
committed
Precompile regex
1 parent 86200bf commit c168dd4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/utils/VersionUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
@SdkInternalApi
2323
public class VersionUtils {
2424

25-
private VersionUtils() {
25+
private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
2626

27+
private VersionUtils() {
2728
}
2829

2930
/**
30-
* Converts a full version string to a major.minor.x format.
31+
* Converts a full version string to a major.minor.x format.
3132
*
3233
* @param version The full version string to convert (e.g., "2.32.1")
3334
* @return The version string in major.minor.x format (e.g., "2.32.x"),
3435
* or the original string if it doesn't match the expected version pattern
3536
*/
3637
public static String convertToMajorMinorX(String version) {
37-
Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
38-
Matcher matcher = pattern.matcher(version);
38+
Matcher matcher = VERSION_PATTERN.matcher(version);
3939

4040
if (matcher.matches()) {
4141
String major = matcher.group(1);
@@ -47,4 +47,5 @@ public static String convertToMajorMinorX(String version) {
4747

4848
return version;
4949
}
50+
5051
}

0 commit comments

Comments
 (0)