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
This commit is contained in:
Kristian Rosenvold 2012-08-24 18:25:16 +00:00
parent b6c679a127
commit cba6b32e6a
1 changed files with 37 additions and 38 deletions

View File

@ -241,9 +241,13 @@ public class StringSearchModelInterpolator
fields.add( new StringField( currentField ) ); fields.add( new StringField( currentField ) );
} }
} }
else if ( List.class.isAssignableFrom( type ) )
{
fields.add( new ListField( currentField ) );
}
else if ( Collection.class.isAssignableFrom( type ) ) 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 ) ) else if ( Map.class.isAssignableFrom( type ) )
{ {
@ -348,10 +352,10 @@ public class StringSearchModelInterpolator
} }
} }
static final class CollectionField static final class ListField
extends CacheField extends CacheField
{ {
CollectionField( Field field ) ListField( Field field )
{ {
super( field ); super( field );
} }
@ -360,52 +364,47 @@ public class StringSearchModelInterpolator
void doInterpolate( Object target, InterpolateObjectAction ctx ) void doInterpolate( Object target, InterpolateObjectAction ctx )
throws IllegalAccessException throws IllegalAccessException
{ {
@SuppressWarnings( "unchecked" ) Collection<Object> c = (Collection<Object>) field.get( target ); @SuppressWarnings( "unchecked" ) List<Object> c = (List<Object>) field.get( target );
if ( c == null || c.isEmpty() ) if ( c == null )
{ {
return; return;
} }
List<Object> originalValues = new ArrayList<Object>( c ); int size = c.size();
try Object value;
for ( int i = 0; i < size; i++ )
{ {
c.clear();
}
catch ( UnsupportedOperationException e )
{
return;
}
for ( Object value : originalValues ) value = c.get( i );
{
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 );
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 else
{ {
c.add( value ); if ( value.getClass().isArray() )
} {
} evaluateArray( value, ctx );
else }
{ else
c.add( value ); {
if ( value.getClass().isArray() ) ctx.interpolationTargets.add( value );
{ }
evaluateArray( value, ctx );
}
else
{
ctx.interpolationTargets.add( value );
} }
} }
} }