mirror of https://github.com/explosion/spaCy.git
* Make the string-store serve const pointers to Utf8Str
This commit is contained in:
parent
7e04c22f8f
commit
d7952634ca
|
@ -31,4 +31,4 @@ cdef class StringStore:
|
||||||
cdef int size
|
cdef int size
|
||||||
cdef int _resize_at
|
cdef int _resize_at
|
||||||
|
|
||||||
cdef Utf8Str* intern(self, char* chars, int length) except NULL
|
cdef const Utf8Str* intern(self, char* chars, int length) except NULL
|
||||||
|
|
|
@ -20,7 +20,7 @@ cdef class StringStore:
|
||||||
|
|
||||||
def __getitem__(self, object string_or_id):
|
def __getitem__(self, object string_or_id):
|
||||||
cdef bytes byte_string
|
cdef bytes byte_string
|
||||||
cdef Utf8Str* utf8str
|
cdef const Utf8Str* utf8str
|
||||||
if isinstance(string_or_id, int) or isinstance(string_or_id, long):
|
if isinstance(string_or_id, int) or isinstance(string_or_id, long):
|
||||||
if string_or_id < 1 or string_or_id >= self.size:
|
if string_or_id < 1 or string_or_id >= self.size:
|
||||||
raise IndexError(string_or_id)
|
raise IndexError(string_or_id)
|
||||||
|
@ -36,7 +36,7 @@ cdef class StringStore:
|
||||||
else:
|
else:
|
||||||
raise TypeError(type(string_or_id))
|
raise TypeError(type(string_or_id))
|
||||||
|
|
||||||
cdef Utf8Str* intern(self, char* chars, int length) except NULL:
|
cdef const Utf8Str* intern(self, char* chars, int length) except NULL:
|
||||||
# 0 means missing, but we don't bother offsetting the index. We waste
|
# 0 means missing, but we don't bother offsetting the index. We waste
|
||||||
# slot 0 to simplify the code, because it doesn't matter.
|
# slot 0 to simplify the code, because it doesn't matter.
|
||||||
assert length != 0
|
assert length != 0
|
||||||
|
|
Loading…
Reference in New Issue