@@ -701,6 +701,13 @@ static ResultBucket getResultBucket(Item &item, bool hasRequiredTypes,
701701 }
702702}
703703
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+
704711static int compareHighPriorityKeywords (Item &a_, Item &b_) {
705712 static CodeCompletionKeywordKind order[] = {
706713 CodeCompletionKeywordKind::kw_let,
@@ -711,16 +718,9 @@ static int compareHighPriorityKeywords(Item &a_, Item &b_) {
711718 CodeCompletionKeywordKind::kw_return,
712719 CodeCompletionKeywordKind::kw_func,
713720 };
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- };
721721
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 () );
724724 return a < b ? -1 : (b < a ? 1 : 0 );
725725}
726726
@@ -736,16 +736,9 @@ static int compareLiterals(Item &a_, Item &b_) {
736736 CodeCompletionLiteralKind::Tuple,
737737 CodeCompletionLiteralKind::NilLiteral,
738738 };
739- auto size = sizeof (order) / sizeof (order[0 ]);
740739
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 ());
749742
750743 if (a != b)
751744 return a < b ? -1 : 1 ;
@@ -816,17 +809,9 @@ static int compareOperators(Item &a_, Item &b_) {
816809 CCOK::NotEqEq, // !==
817810 CCOK::TildeEq, // ~=
818811 };
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- };
827812
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 () );
830815 return a < b ? -1 : (b < a ? 1 : 0 );
831816}
832817
0 commit comments