summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-05-23 00:23:28 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-05-23 00:23:28 (GMT)
commitf070f1cbbcc1ab2bf790173c26a5f022a866ac99 (patch)
tree0f9c9aa815143b0d2eed70b2bb824c808f06cc56 /Lib/email
parent573b44c18f69307d7dbc95c950aab57ef7ea303e (diff)
downloadcpython-f070f1cbbcc1ab2bf790173c26a5f022a866ac99.zip
cpython-f070f1cbbcc1ab2bf790173c26a5f022a866ac99.tar.gz
cpython-f070f1cbbcc1ab2bf790173c26a5f022a866ac99.tar.bz2
Issue #21448: Improve performance of the email feedparser
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/feedparser.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py
index c95b27f..e2e3e96 100644
--- a/Lib/email/feedparser.py
+++ b/Lib/email/feedparser.py
@@ -26,6 +26,7 @@ import re
from email import errors
from email import message
from email._policybase import compat32
+from collections import deque
NLCRE = re.compile('\r\n|\r|\n')
NLCRE_bol = re.compile('(\r\n|\r|\n)')
@@ -52,8 +53,8 @@ class BufferedSubFile(object):
def __init__(self):
# Chunks of the last partial line pushed into this object.
self._partial = []
- # The list of full, pushed lines, in reverse order
- self._lines = []
+ # A deque of full, pushed lines
+ self._lines = deque()
# The stack of false-EOF checking predicates.
self._eofstack = []
# A flag indicating whether the file has been closed or not.
@@ -78,21 +79,21 @@ class BufferedSubFile(object):
return NeedMoreData
# Pop the line off the stack and see if it matches the current
# false-EOF predicate.
- line = self._lines.pop()
+ line = self._lines.popleft()
# RFC 2046, section 5.1.2 requires us to recognize outer level
# boundaries at any level of inner nesting. Do this, but be sure it's
# in the order of most to least nested.
- for ateof in self._eofstack[::-1]:
+ for ateof in reversed(self._eofstack):
if ateof(line):
# We're at the false EOF. But push the last line back first.
- self._lines.append(line)
+ self._lines.appendleft(line)
return ''
return line
def unreadline(self, line):
# Let the consumer push a line back into the buffer.
assert line is not NeedMoreData
- self._lines.append(line)
+ self._lines.appendleft(line)
def push(self, data):
"""Push some new data into this object."""
@@ -119,8 +120,7 @@ class BufferedSubFile(object):
self.pushlines(parts)
def pushlines(self, lines):
- # Reverse and insert at the front of the lines.
- self._lines[:0] = lines[::-1]
+ self._lines.extend(lines)
def __iter__(self):
return self