Refactoring ClangCompleter to use ResultAnd<>
This commit is contained in:
parent
fb62030122
commit
eb7bec4fdd
@ -53,26 +53,6 @@ namespace YouCompleteMe {
|
|||||||
extern const unsigned int MAX_ASYNC_THREADS;
|
extern const unsigned int MAX_ASYNC_THREADS;
|
||||||
extern const unsigned int MIN_ASYNC_THREADS;
|
extern const unsigned int MIN_ASYNC_THREADS;
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// TODO: replace this with ResultAnd from Result.h
|
|
||||||
struct CompletionDataAndResult {
|
|
||||||
CompletionDataAndResult( const CompletionData *completion_data,
|
|
||||||
const Result &result )
|
|
||||||
: completion_data_( completion_data ), result_( result ) {}
|
|
||||||
|
|
||||||
bool operator< ( const CompletionDataAndResult &other ) const {
|
|
||||||
return result_ < other.result_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CompletionData *completion_data_;
|
|
||||||
Result result_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // unnamed namespace
|
|
||||||
|
|
||||||
|
|
||||||
ClangCompleter::ClangCompleter()
|
ClangCompleter::ClangCompleter()
|
||||||
: candidate_repository_( CandidateRepository::Instance() ),
|
: candidate_repository_( CandidateRepository::Instance() ),
|
||||||
threading_enabled_( false ),
|
threading_enabled_( false ),
|
||||||
@ -411,7 +391,7 @@ std::vector< CompletionData > ClangCompleter::SortCandidatesForQuery(
|
|||||||
std::vector< const Candidate * > repository_candidates =
|
std::vector< const Candidate * > repository_candidates =
|
||||||
candidate_repository_.GetCandidatesForStrings( completion_datas );
|
candidate_repository_.GetCandidatesForStrings( completion_datas );
|
||||||
|
|
||||||
std::vector< CompletionDataAndResult > data_and_results;
|
std::vector< ResultAnd< CompletionData* > > data_and_results;
|
||||||
|
|
||||||
for ( uint i = 0; i < repository_candidates.size(); ++i ) {
|
for ( uint i = 0; i < repository_candidates.size(); ++i ) {
|
||||||
const Candidate *candidate = repository_candidates[ i ];
|
const Candidate *candidate = repository_candidates[ i ];
|
||||||
@ -422,7 +402,8 @@ std::vector< CompletionData > ClangCompleter::SortCandidatesForQuery(
|
|||||||
Result result = candidate->QueryMatchResult( query );
|
Result result = candidate->QueryMatchResult( query );
|
||||||
|
|
||||||
if ( result.IsSubsequence() ) {
|
if ( result.IsSubsequence() ) {
|
||||||
CompletionDataAndResult data_and_result( &completion_datas[ i ], result );
|
ResultAnd< CompletionData* > data_and_result( &completion_datas[ i ],
|
||||||
|
result );
|
||||||
data_and_results.push_back( boost::move( data_and_result ) );
|
data_and_results.push_back( boost::move( data_and_result ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -432,9 +413,9 @@ std::vector< CompletionData > ClangCompleter::SortCandidatesForQuery(
|
|||||||
std::vector< CompletionData > sorted_completion_datas;
|
std::vector< CompletionData > sorted_completion_datas;
|
||||||
sorted_completion_datas.reserve( data_and_results.size() );
|
sorted_completion_datas.reserve( data_and_results.size() );
|
||||||
|
|
||||||
foreach ( const CompletionDataAndResult & data_and_result,
|
foreach ( const ResultAnd< CompletionData* > & data_and_result,
|
||||||
data_and_results ) {
|
data_and_results ) {
|
||||||
sorted_completion_datas.push_back( *data_and_result.completion_data_ );
|
sorted_completion_datas.push_back( *data_and_result.extra_object_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
return sorted_completion_datas;
|
return sorted_completion_datas;
|
||||||
|
@ -99,6 +99,19 @@ struct ResultAnd {
|
|||||||
Result result_;
|
Result result_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template< class T >
|
||||||
|
struct ResultAnd<T* > {
|
||||||
|
ResultAnd( const T* extra_object, const Result &result )
|
||||||
|
: extra_object_( extra_object ), result_( result ) {}
|
||||||
|
|
||||||
|
bool operator< ( const ResultAnd &other ) const {
|
||||||
|
return result_ < other.result_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const T* extra_object_;
|
||||||
|
Result result_;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace YouCompleteMe
|
} // namespace YouCompleteMe
|
||||||
|
|
||||||
#endif /* end of include guard: RESULT_H_CZYD2SGN */
|
#endif /* end of include guard: RESULT_H_CZYD2SGN */
|
||||||
|
Loading…
Reference in New Issue
Block a user