Improve performance of ! (replicate) (#1084)
* Implement ! with weighted repeatCycles * reimplement repeatCycles without array filling
This commit is contained in:
parent
deed379dba
commit
34e9d73908
4 changed files with 31 additions and 17 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue