From b53ea06d5f50fb27cbad0846a6c561c822009c26 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Sat, 21 Jul 2012 12:17:29 -0700 Subject: [PATCH] Using 'dup':1 to save expensive dup eliminition Since we are never going to return duplicate candidates to Vim we might as well save some performance by forcing Vim to not search for duplicates --- python/ycm.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/python/ycm.py b/python/ycm.py index 175ad666..a82c85d1 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -23,7 +23,7 @@ import indexer MIN_NUM_CHARS = int( vim.eval( "g:ycm_min_num_of_chars_for_completion" ) ) CLANG_FILETYPES = set( [ 'c', 'cpp', 'objc', 'objcpp' ] ) -MAX_IDENTIFIER_COMPLETIONS_RETURNED = 20 +MAX_IDENTIFIER_COMPLETIONS_RETURNED = 10 class Completer( object ): @@ -94,7 +94,14 @@ class IdentifierCompleter( Completer ): def CandidatesFromStoredRequest( self ): if not self.future: return [] - return self.future.GetResults()[ : MAX_IDENTIFIER_COMPLETIONS_RETURNED ] + completions = self.future.GetResults()[ + : MAX_IDENTIFIER_COMPLETIONS_RETURNED ] + + # We will never have duplicates in completions so with 'dup':1 we tell Vim + # to add this candidate even if it's a duplicate of an existing one (which + # will never happen). This saves us some expensive string matching + # operations in Vim. + return [ { 'word': x, 'dup': 1 } for x in completions ] class ClangCompleter( Completer ): @@ -162,6 +169,7 @@ def CompletionDataToDict( completion_data ): 'abbr' : completion_data.original_string_, 'menu' : completion_data.extra_menu_info_, 'kind' : completion_data.kind_, + 'dup' : 1, # TODO: add detailed_info_ as 'info' }