##// END OF EJS Templates
speedup completion of unicode names
Matthias Bussonnier -
Show More
@@ -156,6 +156,14 b' except ImportError:'
156 # Globals
156 # Globals
157 #-----------------------------------------------------------------------------
157 #-----------------------------------------------------------------------------
158
158
159 # ranges where we have most of the valid unicode names. We could be more finer
160 # grained but is it worth it for performace While unicode have character in the
161 # rage 0, 0x110000, we seem to have name for about 10% of those. (131808 as I
162 # write this). With below range we cover them all, with a density of ~67%
163 # biggest next gap we consider only adds up about 1% density and there are 600
164 # gaps that would need hard coding.
165 _UNICODE_RANGES = [(32, 0x2fa1e), (0xe0001, 0xe01f0)]
166
159 # Public API
167 # Public API
160 __all__ = ['Completer','IPCompleter']
168 __all__ = ['Completer','IPCompleter']
161
169
@@ -2092,7 +2100,7 b' class IPCompleter(Completer):'
2092 full_text = line_buffer
2100 full_text = line_buffer
2093 completions = self._jedi_matches(
2101 completions = self._jedi_matches(
2094 cursor_pos, cursor_line, full_text)
2102 cursor_pos, cursor_line, full_text)
2095
2103
2096 if self.merge_completions:
2104 if self.merge_completions:
2097 matches = []
2105 matches = []
2098 for matcher in self.matchers:
2106 for matcher in self.matchers:
@@ -2195,6 +2203,16 b' class IPCompleter(Completer):'
2195 names.append(unicodedata.name(chr(c)))
2203 names.append(unicodedata.name(chr(c)))
2196 except ValueError:
2204 except ValueError:
2197 pass
2205 pass
2198 self._unicode_names = names
2206 self._unicode_names = _unicode_name_compute(_UNICODE_RANGES)
2199
2207
2200 return self._unicode_names
2208 return self._unicode_names
2209
2210 def _unicode_name_compute(ranges:List[Tuple[int,int]]) -> List[str]:
2211 names = []
2212 for start,stop in ranges:
2213 for c in range(start, stop) :
2214 try:
2215 names.append(unicodedata.name(chr(c)))
2216 except ValueError:
2217 pass
2218 return names
@@ -33,6 +33,19 b' from nose.tools import assert_in, assert_not_in'
33 # Test functions
33 # Test functions
34 # -----------------------------------------------------------------------------
34 # -----------------------------------------------------------------------------
35
35
36 def test_unicode_range():
37 """
38 Test that the ranges we test for unicode names give the same number of
39 results than testing the full length.
40 """
41 from IPython.core.completer import _unicode_name_compute, _UNICODE_RANGES
42
43 expected_list = _unicode_name_compute([(0, 0x110000)])
44 test = _unicode_name_compute(_UNICODE_RANGES)
45
46 assert len(expected_list) == len(test)
47 assert len(expected_list) == 131808
48
36
49
37 @contextmanager
50 @contextmanager
38 def greedy_completion():
51 def greedy_completion():
@@ -230,7 +243,7 b' class TestCompleter(unittest.TestCase):'
230 ip = get_ipython()
243 ip = get_ipython()
231 text, matches = ip.Completer.latex_matches("\\really_i_should_match_nothing")
244 text, matches = ip.Completer.latex_matches("\\really_i_should_match_nothing")
232 nt.assert_equal(text, "")
245 nt.assert_equal(text, "")
233 nt.assert_equal(matches, [])
246 nt.assert_equal(matches, ())
234
247
235 def test_back_latex_completion(self):
248 def test_back_latex_completion(self):
236 ip = get_ipython()
249 ip = get_ipython()
General Comments 0
You need to be logged in to leave comments. Login now