unihandecode: introduce borg to reduce memory consumption

This commit is contained in:
Hiroshi Miura 2011-02-04 00:38:48 +09:00
parent 9fea301a6f
commit 71d91089b6
2 changed files with 16 additions and 0 deletions

View File

@ -163,6 +163,14 @@ class H2a (object):
u"\u3093\u304a":"n'o",
}
# this class is Borg
_shared_state = {}
def __new__(cls, *p, **k):
self = object.__new__(cls, *p, **k)
self.__dict__ = cls._shared_state
return self
def isHiragana(self, char):
return ( 0x3040 < ord(char) and ord(char) < 0x3094)

View File

@ -15,6 +15,14 @@ class jisyo (object):
kanadict = None
jisyo_table = {}
# this class is Borg
_shared_state = {}
def __new__(cls, *p, **k):
self = object.__new__(cls, *p, **k)
self.__dict__ = cls._shared_state
return self
def __init__(self):
if self.kanwadict is None:
dictpath = resources.get_path(os.path.join('localization','pykakasi','kanwadict2.db'))