From ced59ab9eaf33ccf274cb8cf59474f279cd25f63 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 18 Jul 2015 04:10:53 +0200 Subject: [PATCH] * Make minor efficiency improvement in Doc.__iter__ --- spacy/tokens/doc.pyx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index df5a0f6c0..607b71a17 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -134,8 +134,12 @@ cdef class Doc: Yields: token (Token): """ + cdef int i for i in range(self.length): - yield Token.cinit(self.vocab, &self.data[i], i, self) + if self._py_tokens[i] is not None: + yield self._py_tokens[i] + else: + yield Token.cinit(self.vocab, &self.data[i], i, self) def __len__(self): return self.length