@@ -465,15 +465,40 @@ function (acr::ACRule)(term)
465
465
466
466
T = symtype (term)
467
467
args = arguments (term)
468
+ is_full_perm = acr. arity == length (args)
469
+ if is_full_perm
470
+ args_buf = copy (parent (args))
471
+ else
472
+ args_buf = ArgsT (@view args[1 : acr. arity])
473
+ end
468
474
469
475
itr = acr. sets (eachindex (args), acr. arity)
470
476
471
477
for inds in itr
472
- result = r (Term {T} (f, @views args[inds]))
478
+ for (i, ind) in enumerate (inds)
479
+ args_buf[i] = args[ind]
480
+ end
481
+ # this is temporary and only constructed so the rule can
482
+ # try and match it - no need to hashcons it.
483
+ old_hc = ENABLE_HASHCONSING[]
484
+ ENABLE_HASHCONSING[] = false
485
+ tempterm = Term {T} (f, args_buf)
486
+ ENABLE_HASHCONSING[] = old_hc
487
+ # this term will be hashconsed regardless
488
+ result = r (tempterm)
473
489
if result != = nothing
474
490
# Assumption: inds are unique
475
- length (args) == length (inds) && return result
476
- return maketerm (typeof (term), f, [result, (args[i] for i in eachindex (args) if i ∉ inds). .. ], metadata (term))
491
+ is_full_perm && return result
492
+ inds_set = BitSet (inds)
493
+ full_args_buf = ArgsT (@view args[1 : (length (args)- acr. arity+ 1 )])
494
+ idx = 1
495
+ for i in eachindex (args)
496
+ i in inds_set && continue
497
+ full_args_buf[idx] = args[i]
498
+ idx += 1
499
+ end
500
+ full_args_buf[idx] = result
501
+ return maketerm (typeof (term), f, full_args_buf, metadata (term))
477
502
end
478
503
end
479
504
end
0 commit comments