@@ -701,6 +701,13 @@ static ResultBucket getResultBucket(Item &item, bool hasRequiredTypes,
701
701
}
702
702
}
703
703
704
+ template <class T , size_t N>
705
+ static size_t getIndex (const T (&array)[N], T element) {
706
+ auto I = std::find (array, &array[N], element);
707
+ assert (I != &array[N]);
708
+ return std::distance (array, I);
709
+ }
710
+
704
711
static int compareHighPriorityKeywords (Item &a_, Item &b_) {
705
712
static CodeCompletionKeywordKind order[] = {
706
713
CodeCompletionKeywordKind::kw_let,
@@ -711,16 +718,9 @@ static int compareHighPriorityKeywords(Item &a_, Item &b_) {
711
718
CodeCompletionKeywordKind::kw_return,
712
719
CodeCompletionKeywordKind::kw_func,
713
720
};
714
- auto size = sizeof (order) / sizeof (order[0 ]);
715
-
716
- auto getIndex = [=](Item &item) {
717
- auto I = std::find (order, &order[size], cast<Result>(item).value ->getKeywordKind ());
718
- assert (I != &order[size]);
719
- return std::distance (order, I);
720
- };
721
721
722
- auto a = getIndex (a_ );
723
- auto b = getIndex (b_ );
722
+ auto a = getIndex (order, cast<Result>(a_). value -> getKeywordKind () );
723
+ auto b = getIndex (order, cast<Result>(b_). value -> getKeywordKind () );
724
724
return a < b ? -1 : (b < a ? 1 : 0 );
725
725
}
726
726
@@ -736,16 +736,9 @@ static int compareLiterals(Item &a_, Item &b_) {
736
736
CodeCompletionLiteralKind::Tuple,
737
737
CodeCompletionLiteralKind::NilLiteral,
738
738
};
739
- auto size = sizeof (order) / sizeof (order[0 ]);
740
739
741
- auto getIndex = [=](Item &item) {
742
- auto I = std::find (order, &order[size], cast<Result>(item).value ->getLiteralKind ());
743
- assert (I != &order[size]);
744
- return std::distance (order, I);
745
- };
746
-
747
- auto a = getIndex (a_);
748
- auto b = getIndex (b_);
740
+ auto a = getIndex (order, cast<Result>(a_).value ->getLiteralKind ());
741
+ auto b = getIndex (order, cast<Result>(b_).value ->getLiteralKind ());
749
742
750
743
if (a != b)
751
744
return a < b ? -1 : 1 ;
@@ -816,17 +809,9 @@ static int compareOperators(Item &a_, Item &b_) {
816
809
CCOK::NotEqEq, // !==
817
810
CCOK::TildeEq, // ~=
818
811
};
819
- auto size = sizeof (order) / sizeof (order[0 ]);
820
-
821
- auto getIndex = [=](Item &item) {
822
- auto I = std::find (order, &order[size],
823
- cast<Result>(item).value ->getOperatorKind ());
824
- assert (I != &order[size]);
825
- return std::distance (order, I);
826
- };
827
812
828
- auto a = getIndex (a_ );
829
- auto b = getIndex (b_ );
813
+ auto a = getIndex (order, cast<Result>(a_). value -> getOperatorKind () );
814
+ auto b = getIndex (order, cast<Result>(b_). value -> getOperatorKind () );
830
815
return a < b ? -1 : (b < a ? 1 : 0 );
831
816
}
832
817
0 commit comments