From e472b79129e1cc6f90c2261b81466e2aca92941d Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 28 Jun 2019 16:24:44 +0200 Subject: [PATCH] [MNG-6693] Save another few % on a very commonly used method --- .../apache/maven/artifact/ArtifactUtils.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java index 3560d8104f7..389d62b9225 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java @@ -54,7 +54,7 @@ else if ( Artifact.VERSION_FILE_PATTERN.matcher( version ).matches() ) public static String toSnapshotVersion( String version ) { - Validate.notBlank( version, "version can neither be null, empty nor blank" ); + notBlank( version, "version can neither be null, empty nor blank" ); int lastHyphen = version.lastIndexOf( '-' ); if ( lastHyphen > 0 ) @@ -79,8 +79,8 @@ public static String versionlessKey( Artifact artifact ) public static String versionlessKey( String groupId, String artifactId ) { - Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" ); - Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" ); + notBlank( groupId, "groupId can neither be null, empty nor blank" ); + notBlank( artifactId, "artifactId can neither be null, empty nor blank" ); return groupId + ":" + artifactId; } @@ -92,13 +92,22 @@ public static String key( Artifact artifact ) public static String key( String groupId, String artifactId, String version ) { - Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" ); - Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" ); - Validate.notBlank( version, "version can neither be null, empty nor blank" ); + notBlank( groupId, "groupId can neither be null, empty nor blank" ); + notBlank( artifactId, "artifactId can neither be null, empty nor blank" ); + notBlank( version, "version can neither be null, empty nor blank" ); return groupId + ":" + artifactId + ":" + version; } + private static void notBlank( String str, String message ) + { + int c = str != null ? str.charAt( 0 ) : 0; + if ( ( c < '0' || c > '9' ) && ( c < 'a' || c > 'z' ) ) + { + Validate.notBlank( str, message ); + } + } + public static Map artifactMapByVersionlessId( Collection artifacts ) { Map artifactMap = new LinkedHashMap<>();