From cba6b32e6a48701e326c4478d91123800af531c2 Mon Sep 17 00:00:00 2001 From: Kristian Rosenvold Date: Fri, 24 Aug 2012 18:25:16 +0000 Subject: [PATCH] o Changed clumsy collection interpolation into List interpolation, since it's all lists anyway. Performs twice as fast, but you'll have to be a profiler to appreciate this subtle performance increase. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1377020 13f79535-47bb-0310-9956-ffa450edef68 --- .../StringSearchModelInterpolator.java | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java index e7fb57c336..d4bc534618 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java @@ -241,9 +241,13 @@ private boolean isQualifiedForInterpolation( Field field, Class fieldType ) fields.add( new StringField( currentField ) ); } } + else if ( List.class.isAssignableFrom( type ) ) + { + fields.add( new ListField( currentField ) ); + } else if ( Collection.class.isAssignableFrom( type ) ) { - fields.add( new CollectionField( currentField ) ); + throw new RuntimeException("We dont interpolate into collections, use a list instead"); } else if ( Map.class.isAssignableFrom( type ) ) { @@ -348,10 +352,10 @@ void doInterpolate( Object target, InterpolateObjectAction ctx ) } } - static final class CollectionField + static final class ListField extends CacheField { - CollectionField( Field field ) + ListField( Field field ) { super( field ); } @@ -360,52 +364,47 @@ static final class CollectionField void doInterpolate( Object target, InterpolateObjectAction ctx ) throws IllegalAccessException { - @SuppressWarnings( "unchecked" ) Collection c = (Collection) field.get( target ); - if ( c == null || c.isEmpty() ) + @SuppressWarnings( "unchecked" ) List c = (List) field.get( target ); + if ( c == null ) { return; } - List originalValues = new ArrayList( c ); - try + int size = c.size(); + Object value; + for ( int i = 0; i < size; i++ ) { - c.clear(); - } - catch ( UnsupportedOperationException e ) - { - return; - } - for ( Object value : originalValues ) - { - if ( value == null ) - { - // add the null back in...not sure what else to do... - c.add( value ); - } - else if ( String.class == value.getClass() ) - { - String interpolated = ctx.interpolate( (String) value ); + value = c.get( i ); - if ( !interpolated.equals( value ) ) + if ( value != null ) + { + if ( String.class == value.getClass() ) { - c.add( interpolated ); + String interpolated = ctx.interpolate( (String) value ); + + if ( !interpolated.equals( value ) ) + { + try + { + c.set( i, interpolated ); + } + catch ( UnsupportedOperationException e ) + { + return; + } + } } else { - c.add( value ); - } - } - else - { - c.add( value ); - if ( value.getClass().isArray() ) - { - evaluateArray( value, ctx ); - } - else - { - ctx.interpolationTargets.add( value ); + if ( value.getClass().isArray() ) + { + evaluateArray( value, ctx ); + } + else + { + ctx.interpolationTargets.add( value ); + } } } }