StringTransform optimization
productivityindustries opened this issue · 1 comments
productivityindustries commented
while using CodeGuru to profile my own code (java lambda with xray), i got a recommendation for an optimization that pointed to class com.amazonaws.xray.utils.StringTransform and the repeated compilation of REGEX.
The optimization would be very straightforward and it performs 25% faster.
public class StringTransform {
private static final Pattern REGEX = Pattern.compile("([a-z])([A-Z]+)");
private static final String REPLACE = "$1_$2";
public static String toSnakeCase(String camelCase) {
return REGEX.matcher(camelCase).replaceAll(REPLACE).toLowerCase();
}
}
willarmiros commented
@productivityindustries thanks for doing this profile! If you'd like to open a PR with the optimization we'd be happy to approve.