aoye 0.0.22 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/aoye.esm.js CHANGED
@@ -337,66 +337,6 @@ const _scheduler = {
337
337
  globalThis["sche"] = _scheduler[Scheduler.Sync];
338
338
  const registerScheduler = (key, Ctor) => _scheduler[key] = new Ctor();
339
339
 
340
- const DefaultDFSOpt = {
341
- isUp: false,
342
- begin: null,
343
- complete: null,
344
- breakStack: [],
345
- breakLine: null,
346
- breakNode: null
347
- };
348
- function dfs(root, opt = {}) {
349
- const _DefaultDFSOpt$opt = {
350
- ...DefaultDFSOpt,
351
- ...opt
352
- },
353
- isUp = _DefaultDFSOpt$opt.isUp,
354
- begin = _DefaultDFSOpt$opt.begin,
355
- complete = _DefaultDFSOpt$opt.complete,
356
- lineStack = _DefaultDFSOpt$opt.breakStack,
357
- breakLine = _DefaultDFSOpt$opt.breakLine;
358
- let node = opt.breakNode || root;
359
- let line = breakLine;
360
- const listKey = isUp ? "recStart" : "emitStart";
361
- const nodeKey = isUp ? "upstream" : "downstream";
362
- const nextLineKey = isUp ? "nextRecLine" : "nextEmitLine";
363
- const reverseNodeKey = isUp ? "downstream" : "upstream";
364
- while (true) {
365
- let notGoDeep = begin?.({
366
- node,
367
- lineFromUp: line,
368
- walkedLine: lineStack
369
- });
370
- lineStack.push(line);
371
- line = node[listKey];
372
- if (line && !notGoDeep) {
373
- const firstChild = line[nodeKey];
374
- node = firstChild;
375
- continue;
376
- }
377
- while (true) {
378
- const noGoSibling = complete?.({
379
- node,
380
- lineToDeep: line,
381
- walkedLine: lineStack,
382
- notGoDeep
383
- });
384
- line = lineStack.pop();
385
- if (node === root) {
386
- return;
387
- }
388
- notGoDeep = false;
389
- const nextLine = line[nextLineKey];
390
- if (!noGoSibling && nextLine) {
391
- line = nextLine;
392
- node = nextLine[nodeKey];
393
- break;
394
- }
395
- node = line[reverseNodeKey];
396
- }
397
- }
398
- }
399
-
400
340
  class Line {
401
341
  constructor() {
402
342
  /** 上游顶点 */
@@ -585,29 +525,46 @@ function unlinkSingleLine(line) {
585
525
  }
586
526
  function unlinkSingleRefedNode(delRoot) {
587
527
  let toUnlink;
588
- dfs(delRoot, {
589
- isUp: true,
590
- begin: ({
591
- node
592
- }) => {
593
- doUnlink(toUnlink);
594
- toUnlink = null;
595
- if (node.emitStart !== node.emitEnd) {
596
- return true;
597
- }
598
- },
599
- complete: ({
600
- node,
601
- notGoDeep
602
- }) => {
528
+ let node = delRoot,
529
+ i = -1,
530
+ parent;
531
+ const stack = [];
532
+ outer: do {
533
+ let noGoDeep = false;
534
+ doUnlink(toUnlink);
535
+ toUnlink = null;
536
+ noGoDeep = node.emitStart !== node.emitEnd;
537
+ const recStart = node.recStart;
538
+ if (recStart && !noGoDeep) {
539
+ stack[++i] = recStart;
540
+ parent = node;
541
+ node = recStart.upstream;
542
+ continue;
543
+ }
544
+ while (true) {
603
545
  doUnlink(toUnlink);
604
546
  toUnlink = null;
605
- const isSingleRefed = !notGoDeep;
606
- if (isSingleRefed) {
547
+ if (!noGoDeep) {
607
548
  toUnlink = node.emitStart;
608
549
  }
550
+ noGoDeep = false;
551
+ if (i === -1) {
552
+ break outer;
553
+ }
554
+ const backLine = stack[i];
555
+ const nextLine = backLine.nextRecLine;
556
+ if (nextLine) {
557
+ node = nextLine.upstream;
558
+ stack[i] = nextLine;
559
+ break;
560
+ } else {
561
+ node = parent;
562
+ if (--i !== -1) {
563
+ parent = stack[i].downstream;
564
+ }
565
+ }
609
566
  }
610
- });
567
+ } while (true);
611
568
  doUnlink(toUnlink);
612
569
  }
613
570
  function doUnlink(line) {
@@ -622,23 +579,41 @@ function dispose() {
622
579
  const memoNext = toDel.nextRecLine;
623
580
  const upstream = toDel.upstream;
624
581
  if (upstream.state & State.IsScope) {
625
- dfs(upstream, {
626
- isUp: true,
627
- begin: ({
628
- node
629
- }) => {
630
- if ((node.state & State.IsScope) === 0 || node.state & ScopeAbort) return true;
631
- },
632
- complete: ({
633
- node: scope,
634
- notGoDeep
635
- }) => {
636
- const shouldAbort = !notGoDeep;
637
- if (shouldAbort) {
638
- releaseScope(scope);
582
+ let node = upstream,
583
+ i = -1,
584
+ parent;
585
+ const stack = [];
586
+ outer: do {
587
+ let noGoDeep = (node.state & State.IsScope) === 0 || node.state & ScopeAbort;
588
+ const recStart = node.recStart;
589
+ if (recStart && !noGoDeep) {
590
+ stack[++i] = recStart;
591
+ parent = node;
592
+ node = recStart.upstream;
593
+ continue;
594
+ }
595
+ while (true) {
596
+ if (!noGoDeep) {
597
+ releaseScope(node);
598
+ }
599
+ noGoDeep = false;
600
+ if (i === -1) {
601
+ break outer;
602
+ }
603
+ const backLine = stack[i];
604
+ const nextLine = backLine.nextRecLine;
605
+ if (nextLine) {
606
+ node = nextLine.upstream;
607
+ stack[i] = nextLine;
608
+ break;
609
+ } else {
610
+ node = parent;
611
+ if (--i !== -1) {
612
+ parent = stack[i].downstream;
613
+ }
639
614
  }
640
615
  }
641
- });
616
+ } while (true);
642
617
  } else {
643
618
  unlinkSingleLine(toDel);
644
619
  }