summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorTobias Grosser <grosser@fim.uni-passau.de>2013-01-19 11:03:44 +0000
committerTobias Grosser <grosser@fim.uni-passau.de>2013-01-19 11:03:44 +0000
commit69a8552f85c1b926320418cb98fe02988c79578f (patch)
tree5f39ee90943f80698533e506ce39a8b3670a7c65 /bindings
parenteca36d1ae23d0e4c46a3c2c2b91a19f4a2f8055d (diff)
[cindex.py] Add cache for CompletionChunk spellings
Most of the CompletionChunks represent braces, colons or other one character spellings. There is no need to call libclang, to figure out how to write a colon. Instead we use an internal cache to retrieve the correct spelling. As function calls from python are very expensive and this is a performance critical part of auto completion this patch makes formatting of auto completion results a lot faster. Formatting time changes from 0.57 to 0.45 seconds git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172901 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/clang/cindex.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 5e261f8657..446d80d176 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1645,6 +1645,33 @@ class _CXUnsavedFile(Structure):
"""Helper for passing unsaved file arguments."""
_fields_ = [("name", c_char_p), ("contents", c_char_p), ('length', c_ulong)]
+# Functions calls through the python interface are rather slow. Fortunately,
+# for most symboles, we do not need to perform a function call. Their spelling
+# never changes and is consequently provided by this spelling cache.
+SpellingCache = {
+ # 0: CompletionChunk.Kind("Optional"),
+ # 1: CompletionChunk.Kind("TypedText"),
+ # 2: CompletionChunk.Kind("Text"),
+ # 3: CompletionChunk.Kind("Placeholder"),
+ # 4: CompletionChunk.Kind("Informative"),
+ # 5 : CompletionChunk.Kind("CurrentParameter"),
+ 6: '(', # CompletionChunk.Kind("LeftParen"),
+ 7: ')', # CompletionChunk.Kind("RightParen"),
+ 8: ']', # CompletionChunk.Kind("LeftBracket"),
+ 9: ']', # CompletionChunk.Kind("RightBracket"),
+ 10: '{', # CompletionChunk.Kind("LeftBrace"),
+ 11: '}', # CompletionChunk.Kind("RightBrace"),
+ 12: '<', # CompletionChunk.Kind("LeftAngle"),
+ 13: '>', # CompletionChunk.Kind("RightAngle"),
+ 14: ', ', # CompletionChunk.Kind("Comma"),
+ # 15: CompletionChunk.Kind("ResultType"),
+ 16: ':', # CompletionChunk.Kind("Colon"),
+ 17: ';', # CompletionChunk.Kind("SemiColon"),
+ 18: '=', # CompletionChunk.Kind("Equal"),
+ 19: ' ', # CompletionChunk.Kind("HorizontalSpace"),
+ # 20: CompletionChunk.Kind("VerticalSpace")
+}
+
class CompletionChunk:
class Kind:
def __init__(self, name):
@@ -1666,6 +1693,8 @@ class CompletionChunk:
@CachedProperty
def spelling(self):
+ if self.__kindNumber in SpellingCache:
+ return SpellingCache[self.__kindNumber]
return conf.lib.clang_getCompletionChunkText(self.cs, self.key).spelling
# We do not use @CachedProperty here, as the manual implementation is