@@ -69,7 +69,7 @@ public XQMap item(final QueryContext qc, final InputInfo ii) throws QueryExcepti
6969 final XQMap map = toMap (current );
7070 for (final Item key : map .keys ()) {
7171 final Value old = mb != null ? mb .get (key ) : mp .getOrNull (key );
72- final Value val = dups .merge (key , old , map .get (key ));
72+ final Value val = dups .merge (key , old , map .get (key ), qc );
7373 if (val != null ) {
7474 if (mb != null ) mb .put (key , val );
7575 else mp = mp .put (key , val );
@@ -143,7 +143,7 @@ final MapDuplicates duplicates(final MergeOptions options, final QueryContext qc
143143 if (md != null ) return md ;
144144 // function
145145 final Value duplicates = options .get (MergeOptions .DUPLICATES );
146- if (duplicates instanceof FItem ) return new Invoke (toFunction (duplicates , 2 , qc ), qc );
146+ if (duplicates instanceof FItem ) return new Invoke (toFunction (duplicates , 2 , qc ));
147147 // fixed option
148148 final String string = duplicates .isEmpty () ? dflt .toString () : toString (duplicates , qc );
149149 final Duplicates value = Enums .get (Duplicates .class , string );
@@ -152,7 +152,7 @@ final MapDuplicates duplicates(final MergeOptions options, final QueryContext qc
152152
153153 return switch (value ) {
154154 case REJECT -> new Reject ();
155- case COMBINE -> new Combine (qc );
155+ case COMBINE -> new Combine ();
156156 case USE_FIRST -> new UseFirst ();
157157 default -> new UseLast ();
158158 };
@@ -178,7 +178,7 @@ public int hofOffsets() {
178178 */
179179 static final class UseFirst extends MapDuplicates {
180180 @ Override
181- Value get (final Item key , final Value old , final Value value ) {
181+ Value get (final Item key , final Value old , final Value value , final QueryContext qc ) {
182182 return null ;
183183 }
184184 }
@@ -188,7 +188,7 @@ Value get(final Item key, final Value old, final Value value) {
188188 */
189189 static final class UseLast extends MapDuplicates {
190190 @ Override
191- Value get (final Item key , final Value old , final Value value ) {
191+ Value get (final Item key , final Value old , final Value value , final QueryContext qc ) {
192192 return value ;
193193 }
194194 }
@@ -197,19 +197,8 @@ Value get(final Item key, final Value old, final Value value) {
197197 * Concatenate values.
198198 */
199199 static final class Combine extends MapDuplicates {
200- /** Query context. */
201- private final QueryContext qc ;
202-
203- /**
204- * Constructor.
205- * @param qc query context
206- */
207- Combine (final QueryContext qc ) {
208- this .qc = qc ;
209- }
210-
211200 @ Override
212- Value get (final Item key , final Value old , final Value value ) {
201+ Value get (final Item key , final Value old , final Value value , final QueryContext qc ) {
213202 return old .append (value , qc );
214203 }
215204
@@ -224,7 +213,8 @@ SeqType type(final SeqType st) {
224213 */
225214 final class Reject extends MapDuplicates {
226215 @ Override
227- Value get (final Item key , final Value old , final Value value ) throws QueryException {
216+ Value get (final Item key , final Value old , final Value value , final QueryContext qc )
217+ throws QueryException {
228218 throw MERGE_DUPLICATE_X .get (info , key );
229219 }
230220 }
@@ -235,25 +225,22 @@ Value get(final Item key, final Value old, final Value value) throws QueryExcept
235225 final class Invoke extends MapDuplicates {
236226 /** Combiner function. */
237227 private final FItem function ;
238- /** Query context. */
239- private final QueryContext qc ;
240228 /** HOF arguments. */
241- private final HofArgs args ;
229+ private final ThreadLocal < HofArgs > args ;
242230
243231 /**
244232 * Constructor.
245233 * @param function combiner function
246- * @param qc query context
247234 */
248- Invoke (final FItem function , final QueryContext qc ) {
235+ Invoke (final FItem function ) {
249236 this .function = function ;
250- this .qc = qc ;
251- args = new HofArgs (2 );
237+ args = ThreadLocal .withInitial (() -> new HofArgs (2 ));
252238 }
253239
254240 @ Override
255- Value get (final Item key , final Value old , final Value value ) throws QueryException {
256- return function .invoke (qc , info , args .set (0 , old ).set (1 , value ).get ());
241+ Value get (final Item key , final Value old , final Value value , final QueryContext qc )
242+ throws QueryException {
243+ return function .invoke (qc , info , args .get ().set (0 , old ).set (1 , value ).get ());
257244 }
258245
259246 @ Override
0 commit comments