Author: krosenvold Date: Fri Aug 24 18:25:16 2012 New Revision: 1377020 URL: http://svn.apache.org/viewvc?rev=1377020&view=rev Log: 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. Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java?rev=1377020&r1=1377019&r2=1377020&view=diff ============================================================================== --- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java (original) +++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java Fri Aug 24 18:25:16 2012 @@ -241,9 +241,13 @@ public class StringSearchModelInterpolat 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 @@ public class StringSearchModelInterpolat } } - static final class CollectionField + static final class ListField extends CacheField { - CollectionField( Field field ) + ListField( Field field ) { super( field ); } @@ -360,52 +364,47 @@ public class StringSearchModelInterpolat void doInterpolate( Object target, InterpolateObjectAction ctx ) throws IllegalAccessException { - @SuppressWarnings( "unchecked" ) Collection<Object> c = (Collection<Object>) field.get( target ); - if ( c == null || c.isEmpty() ) + @SuppressWarnings( "unchecked" ) List<Object> c = (List<Object>) field.get( target ); + if ( c == null ) { return; } - List<Object> originalValues = new ArrayList<Object>( c ); - try - { - c.clear(); - } - catch ( UnsupportedOperationException e ) + int size = c.size(); + Object value; + for ( int i = 0; i < size; i++ ) { - 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 ) ) - { - c.add( interpolated ); - } - else - { - c.add( value ); - } - } - else + if ( value != null ) { - c.add( value ); - if ( value.getClass().isArray() ) + if ( String.class == value.getClass() ) { - evaluateArray( value, ctx ); + String interpolated = ctx.interpolate( (String) value ); + + if ( !interpolated.equals( value ) ) + { + try + { + c.set( i, interpolated ); + } + catch ( UnsupportedOperationException e ) + { + return; + } + } } else { - ctx.interpolationTargets.add( value ); + if ( value.getClass().isArray() ) + { + evaluateArray( value, ctx ); + } + else + { + ctx.interpolationTargets.add( value ); + } } } }