@@ -532,39 +532,39 @@ private IntersectionRuneType GetRuneTypeForIntersects (ReadOnlySpan<Intersection
532
532
533
533
if ( Has (
534
534
set ,
535
- IntersectionType . PassOverHorizontal ,
536
- IntersectionType . PassOverVertical
535
+ [ IntersectionType . PassOverHorizontal ,
536
+ IntersectionType . PassOverVertical ]
537
537
) )
538
538
{
539
539
return IntersectionRuneType . Cross ;
540
540
}
541
541
542
542
if ( Has (
543
543
set ,
544
- IntersectionType . PassOverVertical ,
544
+ [ IntersectionType . PassOverVertical ,
545
545
IntersectionType . StartLeft ,
546
- IntersectionType . StartRight
546
+ IntersectionType . StartRight ]
547
547
) )
548
548
{
549
549
return IntersectionRuneType . Cross ;
550
550
}
551
551
552
552
if ( Has (
553
553
set ,
554
- IntersectionType . PassOverHorizontal ,
554
+ [ IntersectionType . PassOverHorizontal ,
555
555
IntersectionType . StartUp ,
556
- IntersectionType . StartDown
556
+ IntersectionType . StartDown ]
557
557
) )
558
558
{
559
559
return IntersectionRuneType . Cross ;
560
560
}
561
561
562
562
if ( Has (
563
563
set ,
564
- IntersectionType . StartLeft ,
564
+ [ IntersectionType . StartLeft ,
565
565
IntersectionType . StartRight ,
566
566
IntersectionType . StartUp ,
567
- IntersectionType . StartDown
567
+ IntersectionType . StartDown ]
568
568
) )
569
569
{
570
570
return IntersectionRuneType . Cross ;
@@ -574,38 +574,22 @@ private IntersectionRuneType GetRuneTypeForIntersects (ReadOnlySpan<Intersection
574
574
575
575
#region Corner Conditions
576
576
577
- if ( Exactly (
578
- set ,
579
- IntersectionType . StartRight ,
580
- IntersectionType . StartDown
581
- ) )
577
+ if ( Exactly ( set , CornerIntersections . UpperLeft ) )
582
578
{
583
579
return IntersectionRuneType . ULCorner ;
584
580
}
585
581
586
- if ( Exactly (
587
- set ,
588
- IntersectionType . StartLeft ,
589
- IntersectionType . StartDown
590
- ) )
582
+ if ( Exactly ( set , CornerIntersections . UpperRight ) )
591
583
{
592
584
return IntersectionRuneType . URCorner ;
593
585
}
594
586
595
- if ( Exactly (
596
- set ,
597
- IntersectionType . StartUp ,
598
- IntersectionType . StartLeft
599
- ) )
587
+ if ( Exactly ( set , CornerIntersections . LowerRight ) )
600
588
{
601
589
return IntersectionRuneType . LRCorner ;
602
590
}
603
591
604
- if ( Exactly (
605
- set ,
606
- IntersectionType . StartUp ,
607
- IntersectionType . StartRight
608
- ) )
592
+ if ( Exactly ( set , CornerIntersections . LowerLeft ) )
609
593
{
610
594
return IntersectionRuneType . LLCorner ;
611
595
}
@@ -616,75 +600,75 @@ private IntersectionRuneType GetRuneTypeForIntersects (ReadOnlySpan<Intersection
616
600
617
601
if ( Has (
618
602
set ,
619
- IntersectionType . PassOverHorizontal ,
620
- IntersectionType . StartDown
603
+ [ IntersectionType . PassOverHorizontal ,
604
+ IntersectionType . StartDown ]
621
605
) )
622
606
{
623
607
return IntersectionRuneType . TopTee ;
624
608
}
625
609
626
610
if ( Has (
627
611
set ,
628
- IntersectionType . StartRight ,
612
+ [ IntersectionType . StartRight ,
629
613
IntersectionType . StartLeft ,
630
- IntersectionType . StartDown
614
+ IntersectionType . StartDown ]
631
615
) )
632
616
{
633
617
return IntersectionRuneType . TopTee ;
634
618
}
635
619
636
620
if ( Has (
637
621
set ,
638
- IntersectionType . PassOverHorizontal ,
639
- IntersectionType . StartUp
622
+ [ IntersectionType . PassOverHorizontal ,
623
+ IntersectionType . StartUp ]
640
624
) )
641
625
{
642
626
return IntersectionRuneType . BottomTee ;
643
627
}
644
628
645
629
if ( Has (
646
630
set ,
647
- IntersectionType . StartRight ,
631
+ [ IntersectionType . StartRight ,
648
632
IntersectionType . StartLeft ,
649
- IntersectionType . StartUp
633
+ IntersectionType . StartUp ]
650
634
) )
651
635
{
652
636
return IntersectionRuneType . BottomTee ;
653
637
}
654
638
655
639
if ( Has (
656
640
set ,
657
- IntersectionType . PassOverVertical ,
658
- IntersectionType . StartRight
641
+ [ IntersectionType . PassOverVertical ,
642
+ IntersectionType . StartRight ]
659
643
) )
660
644
{
661
645
return IntersectionRuneType . LeftTee ;
662
646
}
663
647
664
648
if ( Has (
665
649
set ,
666
- IntersectionType . StartRight ,
650
+ [ IntersectionType . StartRight ,
667
651
IntersectionType . StartDown ,
668
- IntersectionType . StartUp
652
+ IntersectionType . StartUp ]
669
653
) )
670
654
{
671
655
return IntersectionRuneType . LeftTee ;
672
656
}
673
657
674
658
if ( Has (
675
659
set ,
676
- IntersectionType . PassOverVertical ,
677
- IntersectionType . StartLeft
660
+ [ IntersectionType . PassOverVertical ,
661
+ IntersectionType . StartLeft ]
678
662
) )
679
663
{
680
664
return IntersectionRuneType . RightTee ;
681
665
}
682
666
683
667
if ( Has (
684
668
set ,
685
- IntersectionType . StartLeft ,
669
+ [ IntersectionType . StartLeft ,
686
670
IntersectionType . StartDown ,
687
- IntersectionType . StartUp
671
+ IntersectionType . StartUp ]
688
672
) )
689
673
{
690
674
return IntersectionRuneType . RightTee ;
@@ -712,7 +696,7 @@ private IntersectionRuneType GetRuneTypeForIntersects (ReadOnlySpan<Intersection
712
696
/// <param name="intersects"></param>
713
697
/// <param name="types"></param>
714
698
/// <returns></returns>
715
- private bool Has ( HashSet < IntersectionType > intersects , params IntersectionType [ ] types )
699
+ private bool Has ( HashSet < IntersectionType > intersects , ReadOnlySpan < IntersectionType > types )
716
700
{
717
701
foreach ( var type in types )
718
702
{
@@ -724,6 +708,25 @@ private bool Has (HashSet<IntersectionType> intersects, params IntersectionType
724
708
return true ;
725
709
}
726
710
711
+
712
+ /// <summary>
713
+ /// Preallocated arrays for <see cref="GetRuneTypeForIntersects"/> calls to <see cref="Exactly"/>.
714
+ /// </summary>
715
+ /// <remarks>
716
+ /// Optimization to avoid array allocation for each call from array params. Please do not edit the arrays at runtime. :)
717
+ ///
718
+ /// More ideal solution would be to change <see cref="Exactly"/> to take ReadOnlySpan instead of an array
719
+ /// but that would require replacing the HashSet.SetEquals call.
720
+ /// </remarks>
721
+ private static class CornerIntersections
722
+ {
723
+ // Names matching #region "Corner Conditions" IntersectionRuneType
724
+ internal static readonly IntersectionType [ ] UpperLeft = [ IntersectionType . StartRight , IntersectionType . StartDown ] ;
725
+ internal static readonly IntersectionType [ ] UpperRight = [ IntersectionType . StartLeft , IntersectionType . StartDown ] ;
726
+ internal static readonly IntersectionType [ ] LowerRight = [ IntersectionType . StartUp , IntersectionType . StartLeft ] ;
727
+ internal static readonly IntersectionType [ ] LowerLeft = [ IntersectionType . StartUp , IntersectionType . StartRight ] ;
728
+ }
729
+
727
730
private class BottomTeeIntersectionRuneResolver : IntersectionRuneResolver
728
731
{
729
732
public override void SetGlyphs ( )
0 commit comments