Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

Repeatedly adding and removing ValueSources and InterpolationPostProcessors from an Interpolator instance incurs O(n) ArrayList.remove() costs. This pattern is common in Maven's model interpolation where temporary value sources are added, used once, then removed.

Changes

Interpolator interface

  • Added interpolate(String, List<ValueSource>, List<InterpolationPostProcessor>) with default SimpleRecursionInterceptor
  • Added interpolate(String, List<ValueSource>, List<InterpolationPostProcessor>, RecursionInterceptor) for full control
  • Used Java 8 default method for convenience overload

All implementations (StringSearchInterpolator, RegexBasedInterpolator, MultiDelimiterStringSearchInterpolator)

  • Refactored private interpolate methods to accept optional value source and post processor lists
  • Falls back to instance lists when provided lists are null or empty
  • Instance state remains unchanged by list-based interpolation

Usage

// Before: O(n) remove operations
interpolator.addValueSource(vs1);
interpolator.addValueSource(vs2);
String result = interpolator.interpolate(input);
interpolator.removeValuesSource(vs1);  // O(n)
interpolator.removeValuesSource(vs2);  // O(n)

// After: direct list passing
List<ValueSource> sources = Arrays.asList(vs1, vs2);
String result = interpolator.interpolate(input, sources, null);

Backward compatible—existing code paths unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>Interpolator interface: allow to interpolate by setting the list of ValueSources and InterpolationPostProcessor</issue_title>
<issue_description>Looking at: https://github.com/apache/maven/blob/a2b800de32cdb9adc1e64a43a0fc32e3ba878103/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java#L233

Adding and removing repeatedly in a list of ValueSources and InterpolationPostProcessor is costly, mainly the final removing ValueSource and InterpolationPostProcessor part since remove is an O(n) operation on an ArrayList.

Instead, modify the Interpolator interface to either directly set both lists and interpolate from there, or either add a new interpolate method that takes both lists as parameters.
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Interpolator interface: allow to interpolate by setting the list of ValueSources and InterpolationPostProcessor Add interpolate methods accepting ValueSource and InterpolationPostProcessor lists Nov 3, 2025
Copilot AI requested a review from slachiewicz November 3, 2025 15:51
Copilot finished work on behalf of slachiewicz November 3, 2025 15:51
@slachiewicz slachiewicz marked this pull request as ready for review November 3, 2025 15:57
@slachiewicz slachiewicz closed this Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interpolator interface: allow to interpolate by setting the list of ValueSources and InterpolationPostProcessor

2 participants