Skip to content

Commit

Permalink
chore: instantiate Pattern once
Browse files Browse the repository at this point in the history
  • Loading branch information
slandelle committed Mar 15, 2024
1 parent f88097f commit 805161a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/io/gatling/mojo/MojoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public final class MojoUtils {

private MojoUtils() {}

private static final Pattern FILE_URL_PATTERN = Pattern.compile("^.*file:(.*)!.*$");

public static String locateJar(Class<?> c) throws Exception {
final URL location;
final String classLocation = c.getName().replace('.', '/') + ".class";
Expand All @@ -38,8 +40,7 @@ public static String locateJar(Class<?> c) throws Exception {
location = loader.getResource(classLocation);
}
if (location != null) {
Pattern p = Pattern.compile("^.*file:(.*)!.*$");
Matcher m = p.matcher(location.toString());
Matcher m = FILE_URL_PATTERN.matcher(location.toString());
if (m.find()) {
return URLDecoder.decode(m.group(1), StandardCharsets.UTF_8);
}
Expand Down

0 comments on commit 805161a

Please sign in to comment.