@@ -560,8 +560,8 @@ func (n *nodeContext) checkTypos() {
560
560
required .replaceIDs (ctx , na .replaceIDs ... )
561
561
}
562
562
563
- required .filterSets (func (a [] reqSet ) bool {
564
- if hasParentEllipsis (a , n .conjunctInfo ) {
563
+ n .filterSets (& required , func (n * nodeContext , a requirement ) bool {
564
+ if hasParentEllipsis (n , a , n .conjunctInfo ) {
565
565
a [0 ].removed = true
566
566
}
567
567
return true
@@ -680,6 +680,8 @@ outer:
680
680
// head. For non-head elements, size is 0.
681
681
type reqSets []reqSet
682
682
683
+ type requirement []reqSet
684
+
683
685
// A single reqID might be satisfied by multiple defIDs, if the definition
684
686
// associated with the reqID embeds other definitions, for instance. In this
685
687
// case we keep a list of defIDs that may also be satisfied.
@@ -894,7 +896,7 @@ func getReqSets(n *nodeContext) reqSets {
894
896
895
897
if p := v .Parent ; p != nil && ! n .dropParentRequirements {
896
898
a = append (a , getReqSets (p .state )... )
897
- a .filterNonRecursive ()
899
+ n .filterNonRecursive (& a )
898
900
}
899
901
900
902
last := len (a ) - 1
@@ -953,9 +955,9 @@ outer:
953
955
// If 'v' is a hidden field, then all reqSets in 'a' for which there is no
954
956
// corresponding entry in conjunctInfo should be removed from 'a'.
955
957
if allowedInClosed (v .Label ) {
956
- a .filterSets (func (a [] reqSet ) bool {
957
- for _ , e := range a {
958
- for _ , c := range n . conjunctInfo {
958
+ n .filterSets (& a , func (n * nodeContext , a requirement ) bool {
959
+ for _ , c := range n . conjunctInfo {
960
+ for _ , e := range a {
959
961
if c .id == e .id {
960
962
return true // keep the set
961
963
}
@@ -970,7 +972,7 @@ outer:
970
972
parentConjuncts = p .state .conjunctInfo
971
973
}
972
974
973
- a .filterTop (n .conjunctInfo , parentConjuncts )
975
+ n .filterTop (& a , n .conjunctInfo , parentConjuncts )
974
976
975
977
n .computedCloseInfo = true
976
978
n .reqSets = a
@@ -979,12 +981,12 @@ outer:
979
981
980
982
// If there is a top or ellipsis for all supported conjuncts, we have
981
983
// evidence that this node can be dropped.
982
- func (a * reqSets ) filterTop (conjuncts , parentConjuncts []conjunctInfo ) (openLevel bool ) {
983
- a .filterSets (func (a [] reqSet ) bool {
984
+ func (n * nodeContext ) filterTop (a * reqSets , conjuncts , parentConjuncts []conjunctInfo ) (openLevel bool ) {
985
+ n .filterSets (a , func (n * nodeContext , a requirement ) bool {
984
986
var f conjunctFlags
985
987
hasAny := false
986
- for _ , e := range a {
987
- for _ , c := range conjuncts {
988
+ for _ , c := range conjuncts {
989
+ for _ , e := range a {
988
990
if e .id != c .id {
989
991
continue
990
992
}
@@ -999,7 +1001,7 @@ func (a *reqSets) filterTop(conjuncts, parentConjuncts []conjunctInfo) (openLeve
999
1001
if (f .hasTop () && ! f .hasStruct ()) || f .forceOpen () {
1000
1002
return false
1001
1003
}
1002
- if ! hasAny && hasParentEllipsis (a , parentConjuncts ) {
1004
+ if ! hasAny && hasParentEllipsis (n , a , parentConjuncts ) {
1003
1005
a [0 ].removed = true
1004
1006
}
1005
1007
return true
@@ -1013,7 +1015,7 @@ func (a *reqSets) filterTop(conjuncts, parentConjuncts []conjunctInfo) (openLeve
1013
1015
// TODO: this is currently called twice. Consider an approach where we only need
1014
1016
// to filter this once for each node. Luckily we can avoid quadratic checks
1015
1017
// for any conjunct that is not an ellipsis, which is most.
1016
- func hasParentEllipsis (a reqSets , conjuncts []conjunctInfo ) bool {
1018
+ func hasParentEllipsis (n * nodeContext , a requirement , conjuncts []conjunctInfo ) bool {
1017
1019
for _ , c := range conjuncts {
1018
1020
if ! c .flags .hasEllipsis () {
1019
1021
continue
@@ -1027,8 +1029,8 @@ func hasParentEllipsis(a reqSets, conjuncts []conjunctInfo) bool {
1027
1029
return false
1028
1030
}
1029
1031
1030
- func (a * reqSets ) filterNonRecursive () {
1031
- a .filterSets (func (e [] reqSet ) bool {
1032
+ func (n * nodeContext ) filterNonRecursive (a * reqSets ) {
1033
+ n .filterSets (a , func (n * nodeContext , e requirement ) bool {
1032
1034
x := e [0 ]
1033
1035
if x .once { // || x.id == 0
1034
1036
e [0 ].ignored = true
@@ -1038,13 +1040,13 @@ func (a *reqSets) filterNonRecursive() {
1038
1040
}
1039
1041
1040
1042
// filter keeps all reqSets e in a for which f(e) and removes the rest.
1041
- func (a * reqSets ) filterSets (f func (e [] reqSet ) bool ) {
1043
+ func (n * nodeContext ) filterSets (a * reqSets , f func (n * nodeContext , e requirement ) bool ) {
1042
1044
temp := (* a )[:0 ]
1043
1045
for i := 0 ; i < len (* a ); {
1044
1046
e := (* a )[i ]
1045
1047
set := (* a )[i : i + int (e .size )]
1046
1048
1047
- if f (set ) {
1049
+ if f (n , requirement ( set ) ) {
1048
1050
temp = append (temp , set ... )
1049
1051
}
1050
1052
0 commit comments