* Fix inefficiency in StringStore.dump function

This commit is contained in:
Matthew Honnibal 2015-07-16 17:34:32 +02:00
parent b59d271510
commit a9c3863665
1 changed files with 6 additions and 6 deletions

View File

@ -108,15 +108,15 @@ cdef class StringStore:
return &self.strings[i] return &self.strings[i]
def dump(self, loc): def dump(self, loc):
strings = []
cdef Utf8Str* string cdef Utf8Str* string
cdef bytes py_string cdef bytes py_string
for i in range(self.size): cdef int i
string = &self.strings[i]
py_string = string.chars[:string.length]
strings.append(py_string.decode('utf8'))
with codecs.open(loc, 'w', 'utf8') as file_: with codecs.open(loc, 'w', 'utf8') as file_:
file_.write(SEPARATOR.join(strings)) for i in range(self.size):
string = &self.strings[i]
py_string = string.chars[:string.length]
file_.write(py_string.decode('utf8'))
file_.write(SEPARATOR)
def load(self, loc): def load(self, loc):
with codecs.open(loc, 'r', 'utf8') as file_: with codecs.open(loc, 'r', 'utf8') as file_: