##// END OF EJS Templates
PERF: Don't compute unicode names until they're needed....
Scott Sanderson -
Show More
@@ -136,7 +136,7 b' from IPython.utils import generics'
136 from IPython.utils.dir2 import dir2, get_real_method
136 from IPython.utils.dir2 import dir2, get_real_method
137 from IPython.utils.path import ensure_dir_exists
137 from IPython.utils.path import ensure_dir_exists
138 from IPython.utils.process import arg_split
138 from IPython.utils.process import arg_split
139 from traitlets import Bool, Enum, Int, Unicode, observe
139 from traitlets import Bool, Enum, Int, List as ListTrait, Unicode, default, observe
140 from traitlets.config.configurable import Configurable
140 from traitlets.config.configurable import Configurable
141
141
142 import __main__
142 import __main__
@@ -1005,8 +1005,6 b' def _make_signature(completion)-> str:'
1005 class IPCompleter(Completer):
1005 class IPCompleter(Completer):
1006 """Extension of the completer class with IPython-specific features"""
1006 """Extension of the completer class with IPython-specific features"""
1007
1007
1008 _names = None
1009
1010 @observe('greedy')
1008 @observe('greedy')
1011 def _greedy_changed(self, change):
1009 def _greedy_changed(self, change):
1012 """update the splitter and readline delims when greedy is changed"""
1010 """update the splitter and readline delims when greedy is changed"""
@@ -1060,6 +1058,22 b' class IPCompleter(Completer):'
1060 default_value=".completion_profiles",
1058 default_value=".completion_profiles",
1061 help="Template for path at which to output profile data for completions."
1059 help="Template for path at which to output profile data for completions."
1062 ).tag(config=True)
1060 ).tag(config=True)
1061
1062 _unicode_names = ListTrait(
1063 Unicode(),
1064 help="Lazily-initialized list of unicode code point names.",
1065 )
1066
1067 @default('_unicode_names')
1068 def _unicode_names_default_value(self):
1069 names = []
1070 for c in range(0,0x10FFFF + 1):
1071 try:
1072 names.append(unicodedata.name(chr(c)))
1073 except ValueError:
1074 pass
1075 return names
1076
1063 @observe('limit_to__all__')
1077 @observe('limit_to__all__')
1064 def _limit_to_all_changed(self, change):
1078 def _limit_to_all_changed(self, change):
1065 warnings.warn('`IPython.core.IPCompleter.limit_to__all__` configuration '
1079 warnings.warn('`IPython.core.IPCompleter.limit_to__all__` configuration '
@@ -2103,19 +2117,17 b' class IPCompleter(Completer):'
2103 return text, _matches, origins, completions
2117 return text, _matches, origins, completions
2104
2118
2105 def fwd_unicode_match(self, text:str) -> Tuple[str, list]:
2119 def fwd_unicode_match(self, text:str) -> Tuple[str, list]:
2106 if self._names is None:
2107 self._names = []
2108 for c in range(0,0x10FFFF + 1):
2109 try:
2110 self._names.append(unicodedata.name(chr(c)))
2111 except ValueError:
2112 pass
2113
2120
2114 slashpos = text.rfind('\\')
2121 slashpos = text.rfind('\\')
2115 # if text starts with slash
2122 # if text starts with slash
2116 if slashpos > -1:
2123 if slashpos > -1:
2124 # PERF: It's important that we don't access self._unicode_names
2125 # until we're inside this if-block. _unicode_names is lazily
2126 # initialized, and it takes a user-noticeable amount of time to
2127 # initialize it, so we don't want to initialize it unless we're
2128 # actually going to use it.
2117 s = text[slashpos+1:]
2129 s = text[slashpos+1:]
2118 candidates = [x for x in self._names if x.startswith(s)]
2130 candidates = [x for x in self._unicode_names if x.startswith(s)]
2119 if candidates:
2131 if candidates:
2120 return s, candidates
2132 return s, candidates
2121 else:
2133 else:
General Comments 0
You need to be logged in to leave comments. Login now