Improve performance of ! (replicate) (#1084)

* Implement ! with weighted repeatCycles
* reimplement repeatCycles without array filling
This commit is contained in:
Alex McLean 2024-05-02 23:37:32 +01:00 committed by GitHub
parent deed379dba
commit 34e9d73908
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 17 deletions

View file

@ -2310,7 +2310,13 @@ export const { iterBack, iterback } = register(
export const { repeatCycles } = register(
'repeatCycles',
function (n, pat) {
return slowcat(...Array(n).fill(pat));
return new Pattern(function (state) {
const cycle = state.span.begin.sam();
const source_cycle = cycle.div(n).sam();
const delta = cycle.sub(source_cycle);
state = state.withSpan((span) => span.withTime((spant) => spant.sub(delta)));
return pat.query(state).map((hap) => hap.withSpan((span) => span.withTime((spant) => spant.add(delta))));
}).splitQueries();
},
true,
true,