]> granicus.if.org Git - clang/commitdiff
[cindex.py] Cache the number of chunks in CompletionString
authorTobias Grosser <grosser@fim.uni-passau.de>
Mon, 20 Aug 2012 10:38:16 +0000 (10:38 +0000)
committerTobias Grosser <grosser@fim.uni-passau.de>
Mon, 20 Aug 2012 10:38:16 +0000 (10:38 +0000)
Without this patch, lib.clang_getNumCompletionChunks is called at
each _iteration_ of a 'for chunk in CompletionString' loop. Now we
call it just once.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162200 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/python/clang/cindex.py

index 0605c2416fd6dcd8db9a060c7e8c8ef60817ff6c..628ade15932c011febcc61c9964a55c2bb433ad4 100644 (file)
@@ -1725,10 +1725,14 @@ class CompletionString(ClangObject):
             return "<Availability: %s>" % self
 
     def __len__(self):
+        self.num_chunks
+
+    @CachedProperty
+    def num_chunks(self):
         return lib.clang_getNumCompletionChunks(self.obj)
 
     def __getitem__(self, key):
-        if len(self) <= key:
+        if self.num_chunks <= key:
             raise IndexError
         return CompletionChunk(self.obj, key)