From e27b912ef98ac974181309b3d3be056ea4c9393b Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 5 Dec 2014 16:31:30 +1100 Subject: [PATCH] * Remove need for confusing _data pointer to be stored on Tokens --- spacy/tokens.pxd | 1 - spacy/tokens.pyx | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spacy/tokens.pxd b/spacy/tokens.pxd index a219c707f..addb1e3e5 100644 --- a/spacy/tokens.pxd +++ b/spacy/tokens.pxd @@ -23,7 +23,6 @@ cdef class Tokens: cdef Pool mem cdef StringStore _string_store - cdef TokenC* _data cdef TokenC* data cdef int length diff --git a/spacy/tokens.pyx b/spacy/tokens.pyx index 06d3eeb99..b474ff6fb 100644 --- a/spacy/tokens.pyx +++ b/spacy/tokens.pyx @@ -40,11 +40,11 @@ cdef class Tokens: # Guarantee self.lex[i-x], for any i >= 0 and x < padding is in bounds # However, we need to remember the true starting places, so that we can # realloc. - self._data = self.mem.alloc(size + (PADDING*2), sizeof(TokenC)) + data_start = self.mem.alloc(size + (PADDING*2), sizeof(TokenC)) cdef int i for i in range(size + (PADDING*2)): - self._data[i] = EMPTY_TOKEN - self.data = self._data + PADDING + data_start[i] = EMPTY_TOKEN + self.data = data_start + PADDING self.max_length = size self.length = 0 @@ -116,8 +116,9 @@ cdef class Tokens: def _realloc(self, new_size): self.max_length = new_size n = new_size + (PADDING * 2) - self._data = self.mem.realloc(self._data, n * sizeof(TokenC)) - self.data = self._data + PADDING + cdef TokenC* data_start = self.data - PADDING + data_start = self.mem.realloc(data_start, n * sizeof(TokenC)) + self.data = data_start + PADDING cdef int i for i in range(self.length, self.max_length + PADDING): self.data[i] = EMPTY_TOKEN